Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Why am i receiving too many argument error with this?

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 10-26-2010
Chubler_XL's Unix or Linux Image
Chubler_XL Chubler_XL is offline Forum Staff  
Moderator
 
Join Date: Oct 2010
Last Activity: 22 May 2015, 7:26 AM EDT
Posts: 3,167
Thanks: 121
Thanked 1,049 Times in 982 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 Unix and Linux 10-26-2010
ctsgnb ctsgnb is offline Forum Advisor  
Registered User
 
Join Date: Oct 2010
Last Activity: 7 April 2015, 6:37 PM EDT
Location: France
Posts: 2,931
Thanks: 81
Thanked 626 Times in 597 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 Unix and Linux 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 Linux
i'm really learning alot now. thanks to you both
Sponsored Links
    #5  
Old Unix and Linux 10-26-2010
Scrutinizer's Unix or Linux Image
Scrutinizer Scrutinizer is offline Forum Staff  
Moderator
 
Join Date: Nov 2008
Last Activity: 22 May 2015, 12:00 PM EDT
Location: Amsterdam
Posts: 10,201
Thanks: 332
Thanked 2,692 Times in 2,408 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 03:05 PM.