in a bash script file, I have set one variable like this:
current_path=`pwd`
sed -i "1s/.*/working_path='$current_path';/" file1.sh
I want to run this script to replace the first line of file1.sh
into working_path='$current_path';
, but the current_path
has the /
and in the sed
command, the /
is predefined in sed
replace pattern.
And I have tried this:
current_path1="${current_path/\//\\\/}"
the above line, I want to replace the /
in variable current_path
into \/
, then input the current_path1
into the sed
command, but also has an error.
Could you give me some advice, please? Thanks.
Try this.
sed -i -e "1s@.*@working_path='$current_path';@" file1.sh
Use @
instead of /
in the substitute command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With