Dan Track wrote:
On 4/7/06, Stuart Sears <stuart@xxxxxxxxxxx> wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dan Track wrote:
On 4/7/06, Paul Howarth <paul@xxxxxxxxxxxx> wrote:
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?
Exit if "command" produces no output:
[ -z "$(command)" ] && exit
Paul.
Hi
Incidentally. What do you have $() instead of just ().
$(command) == `command`
otherwise you would be testing the length of the literal string '(command)'
this way we are running command and testing the length of its output.
Regards
Stuart
- --
Hi
Thanks for that. Although never having used it I thought "(command)"
meant execute the command in a child shell. I thought the pranthesis
represented anew shell. I take it I'm definitely wrong. If I am wrong
then what is the difference between (command)=="" and `command`==""
(command)
does indeed mean execute the command in a child shell.
$(command)
is equivalent to
`command`
and represents the standard output from running command
"(command)"
is the literal text "(command)"
"$(command)" is equivalent to
$(command)
but the quotes guard against spaces in the output from running command
being used by the shell to split the output into multiple words, as
[ -z $(command) ]
would likely generate syntax errors if there were spaces in the output
of running command.
Paul.