|
Home > Archive > Unix Shell > January 2006 > zsh: How to examine exit status of a command?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
zsh: How to examine exit status of a command?
|
|
|
|
The cmp utility has the exit values:
0 The files or byte ranges are identical.
1 The files or byte ranges are different; this includes
the case where one file or range is identical to
the first part of the other. In the latter case, if
-s has not been specified, cmp writes to standard
output that EOF was reached in the shorter file.
>1 An error occurred.
In a script I'm writing I want to be able to distinguish between
the last two cases, but I can't find in the docs for zsh how one
can examine the exit status of a command.
Any cluebricks would be much appreciated!
kj
P.S. Incidentally, is the answer the same for bash?
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
| |
| Stephane CHAZELAS 2006-01-09, 6:02 pm |
| 2006-01-9, 20:02(+00), kj:
>
>
>
> The cmp utility has the exit values:
>
> 0 The files or byte ranges are identical.
> 1 The files or byte ranges are different; this includes
> the case where one file or range is identical to
> the first part of the other. In the latter case, if
> -s has not been specified, cmp writes to standard
> output that EOF was reached in the shorter file.
>
> In a script I'm writing I want to be able to distinguish between
> the last two cases, but I can't find in the docs for zsh how one
> can examine the exit status of a command.
The exit status of the last run command is in the $? variable or
in the $pipestatus array if the last command was a pipeline.
$? == $pipestatus[-1]
$? is POSIX and Bourne; $pipestatus (and arrays) is zsh-specific
--
Stéphane
|
|
|
|
|