sed 脚本中的 Shell 变量 [英] Shell variables in sed script
本文介绍了sed 脚本中的 Shell 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
sed 命令在命令提示符下按预期工作,但在 shell 脚本中不起作用.
The sed command works as expected at the command prompt, but does not work in a shell script.
new_db_name=`echo "$new_db_name" | sed 's/$replace_string/$replace_with/'`
这是为什么,我该如何解决?
Why is that, and how can I fix it?
推荐答案
对 sed
表达式使用双引号.
Use double quotes for the sed
expression.
new_db_name=$(echo "$new_db_name" | sed "s/$replace_string/$replace_with/")
这篇关于sed 脚本中的 Shell 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文