I have a bunch of commands whose execution should only occur after the successful completion of past commands. I initially started using && to get the job done, but that started resulting is some pretty long lines of code.
I decided to try to make a script of my own that could accomplish the same task, but allow me to do it one line at a time. I've called it thenDo
, and here's what I've got:
#!/bin/bash
errorCode=$?
if [[ $errorCode -eq 0 ]]; then
$@
errorCode=$?
fi
return $errorCode
I've tried running this with a bunch of various modifications to see what the value of $?
was at various stages of execution. It looks like this script will always start with a clean slate, as in the starting value of $?
is always 0
.
For now, I've made a function in my .bashrc
, and that seems to work just fine in my shell, but I need this script so that it can be used within other scripts, which are called by other scripts again, and it seems that this function doesn't always persist through various and sometimes nested script invocations.
It would be really nice if I could find a way to do this in its own script instead of a function. Is there any way to make that happen?