我今天注意到 Bashprintf
有一个-v
选项
-v var assign the output to shell variable VAR rather than
display it on the standard output
如果我这样调用它会起作用
$ printf -v var "Hello world"
$ printf "$var"
Hello world
来自管道它不起作用
$ grep "Hello world" test.txt | xargs printf -v var
-vprintf: warning: ignoring excess arguments, starting with `var'
$ grep "Hello world" test.txt | xargs printf -v var "%s"
-vprintf: warning: ignoring excess arguments, starting with `var'