[英]Ability to use variable in bash SED
I'm trying to use sed to add a variable prefix to my command...我正在尝试使用 sed 向我的命令添加变量前缀...
datestamp="$(date +'%D %r %Z')"
prefix=$("$datestamp site=$i space=$number")
prefix=$("site=$i space=$number")
echo test this thing | sed 's/^/$prefix /'
I'm expecting site=abc space=12 test this thing我期待 site=abc space=12 测试这个东西
Simply replace the single quotes for the sed line with double quotes, and that should do the trick.只需用双引号替换 sed 行的单引号,就可以了。
datestamp="$(date +'%D %r %Z')"
prefix="$datestamp site=$i space=$number"
echo test this thing | sed "s@^@$prefix @"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.