用bash变量替换SED试图使用bash脚本中的sed更改文本文件中的值,sed 's/draw($prev_number;n_)/draw($number;n_)/g' file.txt > tmp这将处于for循环中。不知道为什么不行。有什么建议吗?
3 回答
临摹微笑
TA贡献1982条经验 获得超2个赞
'
"
$ # enclose entire expression in double quotes$ sed "s/draw($prev_number;n_)/draw($number;n_)/g" file.txt > tmp $ # or, concatenate strings with only variables inside double quotes$ # this would restrict expansion to relevant portion$ # and prevent accidental expansion for !, backticks, etc$ sed 's/draw('"$prev_number"';n_)/draw('"$number"';n_)/g' file.txt > tmp $ # variable cannot contain arbitrary characters$ # see link in further reading section for details$ a='foo bar'$ echo 'baz' | sed 's/baz/'"$a"'/g'sed: -e expression #1, char 9: unterminated `s' command
二读:
除非您需要在另一个文件中使用它,否则可以使用
慕侠2389804
TA贡献1719条经验 获得超6个赞
sed "s/draw($prev_number;n_)/draw($number;n_)/g" file.txt > tmp
eval
- 3 回答
- 0 关注
- 837 浏览
添加回答
举报
0/150
提交
取消