I am having trouble using sed find/replace with slashes in the find parameter.
Sample contents of test.sh
str=$(sed -n '/^user:/p' /tmp/shadowtest) # find "user:" line in /etc/shadowtest
arr=(${str//:/ }) # explode str with : as delimeter
arr=${arr[1]} # grab the 2nd element
sed -i 's|$arr|XXXXX|g' /tmp/shadowtest # Nothing gets replaced in shadowtest
Sample contents of /tmp/shadowtest
# junk here
user:$6$hcwp49Lr$BjcJYc/nwaufmsOIw4Tw/POaXO4j.0HDLU0:16310:0:99999:7:::
# junk here
When I run the script as is, nothing gets replaced in the shadowtest file. But if I change the sed command to something like
sed -i 's|99999|XXXXX|g' /tmp/shadowtest
it works fine.