Artificial intelligent assistant

How to debug a script by removing the "if"? 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

If the goal is simply to run each function, and bail out of there was any errors, maybe something like this will work:


function bail {
echo "se ha producido un error ($1)"
exit 1
}

function a {
uptime
}

function b {
cat /etc/redhat-release
}

function c {
cat /etc/redhat-release
}

for f in 'a' 'b' 'c'; do
$f || bail "$f: $?"
done


This will run each function, and if an error is encountered, the function name and exit code are sent to the `bail` function, which will print a line and bail out of any additional commands.

I did remove the use of `su` because it was easier to test that way. If you want to automate this, I'd recommend creating a sudo profile to run those commands with elevated privileges in such a way that you only need to enter your password once, or no times at all.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 39749dadf2332ca9f3150ccf2246d6f1