0

NOTE FROM OP: Oops. My mistake. I happened to let grep hunt for something(s) non-existent. Of course I got no output. And yes, this is a dup of another question.

<><><><><><><><><><><><><><><><><><><><>

There are many answers on the web to (most of) this question. The "most of" part is my problem.

How do I capture the output of a command line into a bash array when the command line contains pipe chars, "|"?

 array=($(ps -ef | grep myproc | grep -v grep))

doesn't work. Neither does:

 array=(`ps -ef | grep myproc | grep -v grep`)

(those are backquotes in case your font mangles them).

And, can the given answer be use with array+= syntax?

4

1 回答 1

1
array=($(ps -ef | grep myproc | grep -v grep))

效果很好。您可以在显示数组中的元素数量时检查它

echo ${#array[*]}

或完整的数组

echo ${array[*]}
于 2012-12-27T21:24:52.720 回答