user2632126
user2632126

Reputation: 3

"set --" command to parse output of "ps" command on terminal

I have trying to get pid of a process using "set --" as following: say a process is started with command: java -jar someProg.jar

In a shell script, i can get the processId using this way:

#    
pid_=$(ps -axf | grep  someProg | grep -v grep)

set -- $pid_

echo $1
#

Now , I tried to get pid on terminal by writing command as:

ps -axf | grep  someProg | grep -v grep | set -- | echo $1

But I didn't get anything.

How can i get the output pid using set -- command on terminal.

Thanks

Upvotes: 0

Views: 703

Answers (2)

ceving
ceving

Reputation: 23824

You can neither pipe into set, because it does not support it, nor use tools like xargs, because set is a built-in.

This is all you can do:

set -- $(ps -axf | grep  someProg | grep -v grep) ; echo $1

Btw: you can not pipe into echo either.

Upvotes: 1

Bor Laze
Bor Laze

Reputation: 2506

What about

ps -axf | grep someProg | grep -v grep | awk '{print $1}'

It shows PID of someProg process...

Upvotes: 1

Related Questions