I have a script I wrote that's supposed to replace the URLs referenced in all files in a directory with a local address, and it doesn't seem to be working, and I'm wondering if somebody can provide me some insight and tell me what I'm doing wrong.
My script is as follows:
#!/bin/bash #script to replace OLDSTR with NEWSTR in all files in the directory the script is run from OLDSTR="http://some.external.url/path/to/file" NEWSTR="file:///local/path/to/file" ( shopt -s globstar dotglob; for file in **; do if [[ -f $file ]] && [[ -w $file ]]; then if [ $file != ".fix" ]; then echo "sed -i -- 's#$OLDSTR#$NEWSTR#g' "$file"" sed -i -- 's#$OLDSTR#$NEWSTR#g' "$file" else echo "Skipped self" fi fi done )
Because I'm working with URLs and native unix paths, I opted to use
# as the delimiter for
/ as is frequently used in the answers to other
The loop echoes out each file parsed, correctly matches the script itself and skips it, but no files are actually altered. I've been messing around with this for several days now and really annoyed!