Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当变量有空格时,如何使用 sed 将字符串替换为变量的内容?
例如
sed 's_3_4 5_g' 234
返回 24 54,但是
replace="4 5"; sed 's_3_'$replace'_g' 234
给我错误
sed: 1: "s_3_4": unterminated substitute in regular expression
只需引用变量扩展:
sed 's_3_'"$replace"'_g'