简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM