Please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques.
That's not a very good script. In particular it relies on the
Don't Read Lines With For error. None of the variables are quoted either, the $i variable is never even used, and you have to hard-code the values into the script.
Code:
#!/bin/bash
# **************** Change Variables Here ************
# Alered to use the first 3 arguments by default,
# but will fall back to the entered values if not supplied.
startdirectory="${1:-/your/start/directory}"
searchterm="${2:-test}"
replaceterm="${3:test=ok!}"
# ***************************************************
while IFS='' read -rd '' fname; do
sed -i "/$searchterm/ s/$searchterm/$replaceterm/ig" "$fname"
echo "Modified: $fname"
done < <( grep -R -Z -l "$searchterm" "$startdirectory" )
exit 0