在bash脚本文件,我已成立一个变量是这样的:在bash如何替换字符串变量,并将其设置为sed命令
current_path=`pwd`
sed -i "1s/.*/working_path='$current_path';/" file1.sh
我要运行该脚本,以取代第一线file1.sh
分成working_path='$current_path';
,但current_path
有/
,在sed
命令中,/
是在sed
中预定义的替换模式。 我已经试过这样:
current_path1="${current_path/\//\\\/}"
上面的线,我想更换/
变量current_path
到\/
,然后输入current_path1
到sed
命令,但也有错误。
您能给我一些建议吗?谢谢。
可能重复(http://stackoverflow.com/questions/584894/sed-scripting-environment-variable-substitution) – tripleee
@tripleee,谢谢。这篇文章非常有帮助。当时我可能找不到那个帖子,我面临这个问题。或者我使用了不同的关键字,以便搜索引擎不返回该帖子的索引。于是,我在这里发了一个新帖子。 – mining