在bash脚本文件中,我设置了一个这样的变量:
current_path=`pwd`
sed -i "1s/.*/working_path='$current_path';/" file1.sh
Run Code Online (Sandbox Code Playgroud)
我想运行这个脚本来替换file1.shinto 的第一行working_path='$current_path';,但是在命令中current_path有/和sed,它/是在sed替换模式中预定义的.我试过这个:
current_path1="${current_path/\//\\\/}"
Run Code Online (Sandbox Code Playgroud)
上面这行,我想将/in变量替换current_path成\/,然后输入current_path1到sed命令中,但也有错误.
你能给我一些建议吗?谢谢.
试试这个.
sed -i -e "1s@.*@working_path='$current_path';@" file1.sh
Run Code Online (Sandbox Code Playgroud)
使用@,而不是/在替换命令.