Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Difference between Command Line and KSH script

Status
Not open for further replies.

jmanj

Programmer
May 20, 2003
298
US
In the unix command line(sun solaris), when I enter the following command:
ps -ef|grep ScanFileClient|grep -v grep|tr -s ' '|cut -d ' ' -f 3,10,12

I get the result as:

5576 ScanFileClient CB123
5577 ScanfileClient CB124

However if I put the following same command in a ksh script:

for i in `ps -ef|grep ScanFileClient|grep -v grep|tr -s ' '|cut -d ' ' -f 3,10,12`;do

echo " $i Active"

done


I get the result as:

5576 Active
ScanFileClient Active
CB123 Active
5577 Active
ScanFileClient Active
CB124 Active


What is the difference?? All I wanted is the result should be

5576 ScanFileClient CB123 Active
5577 ScanFileClient CB124 Active


Any help will be appreciated.

jmanj
 
How about:

[tt]ps -ef|grep ScanFileClient|grep -v grep|tr -s ' '|cut -d ' ' -f 3,10,12 | xargs -n1 -i echo {} Active[/tt]

When you use the `backticks` around a command the output is concatenated, all one line, separated by spaces, e.g.

[tt]for i in 5576 ScanFileClient CB123 5577 ScanfileClient CB124;do
[/tt]

Then your for loop processes each word separately.

Annihilannic.
 
Annihilannic

It works!!!!!

Thank you so much.

jmanj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top