On Thu, Jan 20, 2000 at 12:23:09PM -0700, SoloCDM wrote:
| 1) Is it possible to effectively determine if a command executed
| successfully or failed?

Sure. Every command has an exit status, which is zero on success and
nonzero on failure (some commands have a well documented assortment of
nonzero exits for different types of failure in the manual entry,
though most simply exit with a 1 for all failures).

The shell stores in in the variable $? when the command completes:

        some command
        echo "exit status was $?"

However, it's cleaner to note that the shell considers commands to be its
expression components, thus:

        if some command
        then  echo "The command worked."
        else  echo "The command failed."
        fi

        some command || echo "The command failed."

        some command && echo "The command succeeded."

The "test" (aka "[") command is constructed around this principle, so
the common:

        if [ some test expression ]
        then
            blah
        fi

is just a special case - that [ ... ] isn't some special shellism,
you're just running the command "[".

| 2) If so, does it work on every command?

It's supposed to. If it doesn't, file a bug report with the author.
BTW, the "make" command depends very heavily on this behaviour, as the
make is meant to stop if some subcommand fails.
-- 
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Courage is not the absence of fear, but rather the judgment that something
else is more important than fear.       - Ambrose Redmoon


-- 
To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe"
as the Subject.

Reply via email to