1

如何在bash中将echo分配给变量

我有简单的命令:

 echo "foo=bar" | cut -d "=" -f1

从某些琴弦上切下一些琴弦

如何将此结果分配给某个变量?

没事

(echo "foo=bar" | cut -d "=" -f1) $test=`(echo "foo=bar" | cut -d "=" -f1)` $test=`$(echo "foo=bar" | cut -d "=" -f1)` $test="$(echo "foo=bar" | cut -d "=" -f1)"

输出:

 foo script.sh: 14: =foo: not found script.sh: 1: foo: not found script.sh: 15: =: not found script.sh: 16: =foo: not found

已提交 March 17th 2021 通過 Admin

答案
0

您可以使用$()命令替换):

 test=$(echo "foo=bar" | cut -d "=" -f1) echo "$test" foo

Admin | 7个月前



枪支相关




文本文件的单独列

November 26th 2020