我是靠谱客的博主 听话樱桃,这篇文章主要介绍linux sed 变量替换,用bash变量替换SED,现在分享给大家,希望可以做个参考。

内部变量'不要被取代。要获得字符串替换(或者内插法,如果您熟悉Perl),需要将其更改为使用双引号"而不是单引号:$ # 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

二读:

最后

以上就是听话樱桃最近收集整理的关于linux sed 变量替换,用bash变量替换SED的全部内容,更多相关linux内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(47)

评论列表共有 0 条评论

立即
投稿
返回
顶部