Trying to search and replace password variables with special characters in multiple files with a perl
command in a bash script. So far I have:
grep -rlF "${old_pass}" | xargs perl -p -e "s~Q$old_pass~E$new_pass~g"
and it works for most cases, however sometimes it fails. For example, given old_pass=*DGB9Twq7WTwz@wR
and new_pass=tDx6U&ShRv}E3Mdb
the above command results in tDx6U&ShRv}E3Mdb@wR
instead of just tDx6U&ShRv}E3Mdb
.
Please note that passwords are generated automatically and can consist of all uppercase and lowercase letters, numbers and all special characters. So the working version must be able to take into account (escape) all kind of possible password versions.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…