Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
ps -ef | while read line; do
    for i in $line; do
        if [ $i = 'bash' ]; then
            echo $line;
unset i;

The command runs properly displaying the Bash processes but an additional Bash process is being created and displayed. I'm hoping it has something to do inside the if checking. I tried to run it with/without single/double quotes both for $i and bash inside the if condition. The process is still being created and shown. I could have used grep to get the output but wanted to try it this way.

Pls correct me.

share|improve this question
What are you really trying to do? Most likely you want to use pgrep or a dedicated library instead. Manually parsing ps output is not what it's for, not least because of issues like this. – Daniel Andersson Oct 3 '13 at 10:52

The extra process is created by the pipe.

For more information read this very good explanation of bash and the process tree.

Note that the output of ps is not designed to be parseable. When trying to parse ps you are most likely better of using pgrep.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .