In Bash I’m executing a command and putting the result in a variable like this:
export var=`svn ls`
But if SVN fails for some reason–say it returns a non-zero error code–export still returns status code 0. How do I detect if the executed command fails?
$?is the exit code of the last command executed, which issvn lshere.jmohr’s solution is short and sweet. Adapted mildly,
would be approximately equivalent to the above (
exportof a valid identifier will never fail, unless you’ve done something horrible and run out of environment space). Take whatever you want — I useunsetjust to avoid$varpossibly having a value even though it’s not exported.