Why am i receiving too many argument error with this? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Why am i receiving too many argument error with this?

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-26-2010
garfish garfish is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 23 September 2012, 2:25 AM EDT
Posts: 16
Thanks: 5
Thanked 0 Times in 0 Posts
Why am i receiving too many argument error with this?


Code:
#!/bin/bash
while [ `ps -ef | grep firefox-bin` ]
do
codes
done

it says line 2: [: too many arguments
why?

Last edited by pludi; 10-27-2010 at 03:10 AM..
Sponsored Links
    #2  
Old 10-26-2010
Chubler_XL's Avatar
Chubler_XL Chubler_XL is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 25 July 2014, 2:43 AM EDT
Posts: 2,741
Thanks: 103
Thanked 848 Times in 799 Posts
output of ps is going into test ([) eg:


Code:
[ root   2104    1   con 09:05:06   /usr/local/bin/firfox-bin  root   2106 2104   con 09:05:06   /usr/local/bin/firfox-bin ]

Perhaps this is something more like what you wanted:


Code:
ps -ef | grep firfox-bin | while read ps_line
do
    codes (that uses $ps_line)
done


Last edited by Chubler_XL; 10-26-2010 at 08:11 PM.. Reason: fix typos
Sponsored Links
    #3  
Old 10-26-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 26 June 2014, 10:29 AM EDT
Location: France
Posts: 2,930
Thanks: 81
Thanked 624 Times in 596 Posts

Code:
while ( ps -ef | grep firefox-bin | grep -v grep 2>/dev/null )
do
     code
done

code will be executed as long as the grep find the pattern in the process list so (i suppose) as long as some firefox processes are found

Last edited by ctsgnb; 10-26-2010 at 08:38 PM..
    #4  
Old 10-26-2010
garfish garfish is offline
Registered User
 
Join Date: Sep 2010
Last Activity: 23 September 2012, 2:25 AM EDT
Posts: 16
Thanks: 5
Thanked 0 Times in 0 Posts
lolz
i'm really learning alot now. thanks to you both
Sponsored Links
    #5  
Old 10-26-2010
Scrutinizer's Avatar
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 24 July 2014, 4:49 PM EDT
Location: Amsterdam
Posts: 9,281
Thanks: 260
Thanked 2,303 Times in 2,066 Posts
Or:

Code:
while ps -ef | grep -q [f]irefox-bin
do
   sleep 10
done

The use of square brackets is important or grep may grep itself.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Argument too long list error 22karthikreddy Shell Programming and Scripting 1 09-27-2010 01:12 AM
Receiving error: ./ang.ksh[35]: 0403-057 Syntax error at line 116 : `done' is not expected. amitsinha Shell Programming and Scripting 3 05-25-2010 02:44 AM
Non Numeric Argument Error Allenzo UNIX for Dummies Questions & Answers 4 08-04-2008 10:40 AM
ERROR-> test: argument expected , what does it mean? tan102938 Shell Programming and Scripting 4 09-21-2006 11:20 PM
Receiving error on Unix server-- java.lang.UnsatisfiedLinkError: registerNatives loveToBlade UNIX for Dummies Questions & Answers 4 08-23-2006 06:00 AM



All times are GMT -4. The time now is 04:19 AM.