【发布时间】:2018-01-04 15:14:57
【问题描述】:
#!/bin/bash
# 1st part
ret=$(ps aux | grep -v grep) # thats OK
echo $ret
# 2nd part
cmd="ps aux | grep -v grep" # a problem with the pipe |
ret=$($cmd)
echo $ret
如何使用第二部分中的命令字符串?认为管道是问题。试图逃脱它,但它没有帮助。得到一些 ps 的语法错误。
谢谢!
【问题讨论】:
-
这是由求值顺序造成的,例如here。
-
另见BashFAQ #50。
-
(说到,我们每周收到的常见问题解答怎么能达到 +5?!)
标签: bash