I have the following code:
debug=$?
function a {
su - javi -c "uptime"
return $debug
}
function b {
su - javi -c "cat /etc/redhat-release"
return $debug
}
function c {
su - javi -c "cat /etc/redhat-release"
return $debug
}
case $debug in
0)
a
if [ $debug == 0 ]; then
b
echo "se ejcuta la funcion"
elif [ $debug == 0 ]
c
elif[].... <-----this
fi
;;
1)
echo "se ha producido un error"
;;
esac
Is there any way to debug by removing the if ??I want them to go running a function if it ends well that jumps to the other function and if it does not end well that it leaves the escript, that with 5 functions
ìf false ; then
followed by# if
?su
operation to runuptime
or to read/etc/redhat-release
. And why do youreturn $debug
from your functions when it's a global variable, and you ignore the return value anyway?$?
... not sure what that would be in a new subshell. is it just the value of the last command run?false; ./myscript.sh
to enable debug ortrue; ./myscript.sh
to keep it off. But it would also get triggered with two commands such asls /does/not/exist
then./myscript.sh
[
and]
characters, for starters. And==
is a string comparison. Use-eq
for a numeric one.