[英]Bash awk one-liner not printing
期望这能打印出abc-但我什么也没得到,每次都没有。
echo abc=xyz | g="$(awk -F "=" '{print $1}')" | echo $g
A pipeline isn't a set of separate assignments. 管道不是一组单独的分配。 However, you could rewrite your current code as follows: 但是,您可以按以下方式重写当前代码:
result=$(
echo 'abc=xyz' | awk -F '=' '{print $1}'
)
echo "$result"
However, a more Bash-centric solution without intermediate assignments could take advantage of a here-string. 但是,在没有中间分配的情况下,以Bash为中心的解决方案可以利用here字符串。 For example: 例如:
awk -F '=' '{print $1}' <<< 'abc=xyz'
Other solutions are possible, too, but this should be enough to get you started in the right direction. 也可以使用其他解决方案,但这应该足以使您朝正确的方向开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.