bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: return values of bash scripts


From: kc123
Subject: Re: return values of bash scripts
Date: Wed, 21 Dec 2011 08:11:05 -0800 (PST)

Thanks Bob. Awesome! The matching string example below did the trick. 

Bob Proulx wrote:
> 
> Mike Frysinger wrote:
>> kc123 wrote:
>> > For example, my script below called crond.sh:
>> > ...
>> > content=`ps auxw | grep [c]rond| awk '{print $11}'`
>> > ...
>> > and output is:
>> > CONTENT: /bin/bash /bin/bash crond
>> > 
>> > Why are there 2 extra arguments printed (/bin/bash) ?
>> 
>> because you grepped your own script named "crond.sh"
>> 
>> make the awk script smarter, or use pgrep
> 
> You are using a system that supports various ps options.  The
> equivalent of the BSD 'ps aux' is the SysV 'ps -ef'.  They are
> similar.  But then instead of using 'ps aux' BSD style try not
> printing the full path by using 'ps -e'.  You are matching your own
> grep becuase it is in the argument list.
> 
> Then this can be made smarter by simply matching it as a string
> instead of as a pattern.
> 
>   ps -e | awk '$NF=="crond"'
> 
>   ps -e | awk '$NF=="crond"{print$1}'
> 
> Bob
> 
>  
> 

-- 
View this message in context: 
http://old.nabble.com/return-values-of-bash-scripts-tp33012795p33017874.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]