ksh 不计算反引号内的变量
这个把我难住了。
#!/bin/ksh
AWKSCRIPT='END { print "all done"; }'
OUTPUT=`echo hello world | awk '$AWKSCRIPT'`
RETVAL=$?
echo "running echo hello world | awk '$AWKSCRIPT'"
echo "Output = $OUTPUT"
echo "returned = $RETVAL"
输出是
$ ./kshawk.ksh
Output = hello world
returned = 0
(我期望看到“输出=全部完成”)
看起来解释器在评估表达式时没有替换 AWKSCRIPT 变量(如果我使用 $(...) 而不是反引号,我会得到相同的行为) 。
虽然我可以将 AWKSCRIPT 转储到临时文件 - 这也必须进行硬编码吗?
有什么想法如何在反引号内插入变量吗?
This one has me stumped.
#!/bin/ksh
AWKSCRIPT='END { print "all done"; }'
OUTPUT=`echo hello world | awk '$AWKSCRIPT'`
RETVAL=$?
echo "running echo hello world | awk '$AWKSCRIPT'"
echo "Output = $OUTPUT"
echo "returned = $RETVAL"
The output is
$ ./kshawk.ksh
Output = hello world
returned = 0
(I was expecting to see "Output = all done")
It looks like the interpreter is not substituting the AWKSCRIPT variable when evaluating the expression (I get the same behaviour if I use $(...) instead of backticks).
While I could dump AWKSCRIPT to a temporary file - this would have to be hardcoded too?
Any ideas how to interpolate a variable within backticks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
'$AWKSCRIPT'
周围的单引号可防止变量的插值。双引号允许插值:The single quotes around
'$AWKSCRIPT'
prevent the interpolation of the variable. Double quotes do allow interpolation: