-1

When I run the command ps -ef | grep -i this | head -n 1 | awk '{print $2}' in my terminal, it gives me the correct output which gives me the PID that I need from 'this' service.

But when I try to place it in a shell script variable PID=ps -ef | grep stress | head -n 1 | awk '{print $2}' and try to run the script, the output is line 9: -ef: command not found

Help!

1 Answers1

0

In order to have the output of the ps command read into the variable PID, you will need to use $() and so:

PID=$(ps -ef | grep stress | head -n 1 | awk '{print $2}')
Raman Sailopal
  • 12,320
  • 2
  • 11
  • 18