arm*_*inb 8 linux variables bash xargs
如何将全局脚本变量传递给xargs的命令?我这样试过:
TEST=hallo2
echo "hallo" | xargs sh -c 'echo passed=$1 test=$TEST' sh
Run Code Online (Sandbox Code Playgroud)
输出:
passed=hallo test=
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用{}令牌,但我需要这样做!
我正在使用bash.
And*_*er2 10
$TEST从引号中取出变量:
TEST=hallo2
echo "hallo" | xargs sh -c 'echo passed=$1 test='$TEST sh
Run Code Online (Sandbox Code Playgroud)
添加为@ chepner建议的答案.
export变量TEST:
export TEST=hallo2
echo "hallo" | xargs sh -c 'echo passed=$1 test="$TEST"' sh
Run Code Online (Sandbox Code Playgroud)