108   ps --ppid $process | while read -r line ; do
109      #echo $line | awk '{print $1;}
110      child=$($line | awk '{print $1;}')
111      echo $child
113   done

Running this code gives me the following error:

line 111: 3405: command not found

But if I uncomment line 109 it prints the correct value without an error

  • 1
    What are you expecting to happen? without the echo $line will be treated as a command to run, apparently the command 3405 in your example. – Eric Renouf Nov 27 '16 at 1:52
  • 3
    This smacks of an XY problem to me, what is it that you're actually trying to do? – Eric Renouf Nov 27 '16 at 1:54
  • 1
    line 110 looks fishy to me (did you mean to 'echo $line' to awk?) – Jeff Schaller Nov 27 '16 at 2:00
  • 1
    Post complete code that reproduces the problem and explain what you want the script to do. – Gilles 'SO- stop being evil' Nov 27 '16 at 21:19

The issue is that you're not actually giving the value in $line to awk. Instead you try to execute it as a command.

If all you want to do is output the child processes of a process with a certain PID, then you don't need to loop:

ps --ppid "$process" -o pid=

This would get the list of processes that has $process as their PPID, and for each output their PID.

Also related:


Fix it...

ps --ppid $process | while read -r line ; do
  child=$(echo $line | awk '{print $1}')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.