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: Bob Proulx
Subject: Re: return values of bash scripts
Date: Tue, 20 Dec 2011 17:20:15 -0700
User-agent: Mutt/1.5.21 (2010-09-15)

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

Attachment: signature.asc
Description: Digital signature


reply via email to

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