Bash Help
Stuart Sears
stuart at sjsears.com
Fri Apr 7 11:25:35 UTC 2006
-----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
To err is human, to forgive is Not Company Policy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFENkwvamPtx1brPQ4RAjs2AJ9DNo8ZcYyEeiMB+Sul5T1PkvHLDQCdETLH
yA4OslcedcHH2U4RP4EC4UU=
=E42c
-----END PGP SIGNATURE-----
More information about the users
mailing list