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?

Community
  • 1
  • 1
Wes Miller
  • 2,191
  • 2
  • 38
  • 64

1 Answers1

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

works perfectly well. You can check it when you show the number of elements in your array

echo ${#array[*]}

or the complete array with

echo ${array[*]}
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198