[CentOS] Getting the return value of the last command run
fred smith
fredex at fcshome.stoneham.ma.us
Mon May 30 22:14:43 UTC 2011
On Mon, May 30, 2011 at 05:38:56PM +0300, Dotan Cohen wrote:
> All commands return a value, usually 0 if run properly. For instance, try:
> $ ls && echo "done"
> $ lsd && echo "done"
>
> The echo command is only executed if the ls command exited
> successfully. If one did not add the echo command with the && after a
> command, how can he determine if the command exited successfully? I
> have a particularly troubling script that gives does not mention if it
> exits successfully or not. I could modify it (and probably will some
> day) but in general I'd like to know the answer to this question as a
> learning experience.
Yes, all commands return a value UNLESS it was written by one of the
idi,... er, misguided programmers who thinks its ok to write (in
C):
void main (void)
{
...
exit();
}
because, of course, in C main() always returns SOMETHING.
I'm sure it's the same in a bash script, even if the script doesn't
explicitly provide a return value I imagine the shell returns something
anyway, it's just that it's meaningless when that happens.
--
---- Fred Smith -- fredex at fcshome.stoneham.ma.us -----------------------------
I can do all things through Christ
who strengthens me.
------------------------------ Philippians 4:13 -------------------------------
More information about the CentOS
mailing list