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 '/Jagan/s/Hi/HELLO/' file
sed '/Jagan/s/Hi/HELLO/' file
在这里我想Hi用一个变量替换
Hi
var1=Hi sed '/Jagan/s/$var1/HELLO/' file
使用"代替':
"
'
sed "/Jagan/s/$var1/HELLO/"
编辑:双引号"允许外壳扩展字符串内的变量。单引号'不允许这样做。