Bash Help

Dan Track dan.track at gmail.com
Fri Apr 7 11:26:33 UTC 2006


On 4/7/06, Stuart Sears <stuart at sjsears.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dan Track wrote:
> > Hi
> >
> > Simple question, I'm running a command `command`, what I'd like to do
> > is check to see if the response is empty then exit. Does anyone know
> > how I can perform that check?
>
> by empty, I presume you mean 'prints nothing to stdout' ?
>  - you can test the length of a string like this:
> (man test)
>
> if [ -z "$(grep foo /boot/grub/grub.conf)" ] ; then
>   echo "response is empty"
>   exit 1
> else
>   echo "response was not empty"
> fi
>
> or do you mean 'command does not work'
> you can test for a non-zero return code like this:
>
> if [ $(grep 'foo' /boot/grub/grub.conf) ]; then
>   echo "yes"
> else
>   echo "no"
> fi
>
>
> the two tests are similar but not identical
>
> $(command) is exactly the same as `command`
>
> any use?
>
> Stuart
>
> - --
> Stuart Sears RHCA RHCX

Hi

Great. That did the job.

Sorry I meant "prints nothing to stdout".

Many thanks to everyone.
Dan




More information about the fedora-list mailing list