I've a file inside which I have a placeholder text for a password. I'm now trying to find and replace the placeholder text with the actual password. The text looks like below:
USER_GIVEN_PASSWORD=<my_password>
Let's say my password is: ABC&12345
I'm using the below command inside a script to replace this:
sed -i "s/<my_password>/$1/g" file.txt
I pass the input to my script as below:
sh password_replace.sh ABC&12345
My expected output is:
USER_GIVEN_PASSWORD=ABC&12345
But I'm getting the below output:
USER_GIVEN_PASSWORD=ABC<my_password>12345
Clearly, I'm doing something wrong with the &
symbol present in my password. So, when I tried with escaping &
in my input as follows, it actually works:
sh password_replace.sh ABC'\&'12345
But the problem is I should not adjust the input parameter to pass an escape character because the password won't be manually typed. It will automatically come from something like the Azure key vault as the input to my script.
So, I need to make the sed
command itself handle the incoming special characters.
Can someone please help me achieve this?