> In article
> <dfece208-6b8e-4399-b350-fc85d21a8
...@e2g2000vbb.googlegroups.com>,
> DennisW <dennistwilliam...@gmail.com> wrote:
> > On Dec 20, 3:58 pm, kc <keecc...@gmail.com> wrote:
> > > Hi,
> > > Could someone please help me figure out why:
> > > GNU bash, version 3.2.25(1)-release-(x86_64-redhat-linux-gnu)
> > > 1) Why when I do an echo, I get /bin/sh returned as well ?
> > > For example, my script below:
> > > #!/bin/bash
> > > SERVICE='crond'
> > > HOST=`hostname`
> > > content=`ps auxw | grep [c]rond| awk '{print $11}'`
> > > echo "CONTENT:" $content
> > > and output is:
> > > CONTENT: /bin/bash /bin/bash crond
> > > Why are there 2 extra arguments printed ?
> > > Also how do I get rid of the "/bin/bash /bin/bash" and just have
> > > "crond" as output ?
> > > 2) I get a different output from the same script if I run snmpwalk:
> > > part of the script:
> > > $PLACE.1.1) echo "string"; echo `bash /directory/crond.sh`; exit 0 ;;
> > > STRING: "CONTENT: /bin/sh bash bash crond
> > > Why are there 3 extra arguments printed this time. Would like to just
> > > output "crond".
> > > Many thanks.
> > Use more quotes.
> > The square brackets in your grep command are being stripped by the
> > shell.
> While it's a good recommendation, it's not the problem this time. The
> brackets would only be stripped if there's a file named "crond" in his
> current directory.
> imac:barmar $ echo [c]rond
> [c]rond
> imac:barmar $ touch crond
> imac:barmar $ echo [c]rond
> crond
> When a glob doesn't match anything, it's left alone.
> And even if the brackets were stripped, it wouldn't be the cause of this
> symptom. The purpose of the "grep [c]rond" idiom is to avoid matching
> the grep process, but that's not the problem he's having.
> > #!/bin/bash
> > service='crond'
> > host=$(hostname)
> > content=$(ps auxw | grep '[c]rond' | awk '{print $11}')
> > echo "CONTENT: $content"
> > Also use $() instead of the archaic backticks.
> > Use pgrep if you have it.
> > Use lowercase or mixed case variable names. Only use all-caps variable
> > names for system-defined environment and shell variables.
> --
> Barry Margolin, bar...@alum.mit.edu
> Arlington, MA
> *** PLEASE post questions in newsgroups, not directly to me ***