I'm trying to let a command run in the background, but also use the "||" syntax to execute a different command if the first one failed. Example:
$( <run-this-in-background> & || <run-this-if-failed>)
However I'm getting a syntax error:
command substitution: line 15: syntax error near unexpected token `||'
This is the exact line:
$(./temptwo.sh & || rc=$?)
My full code is as follows...
I know it seems a bit weird to do
rc=$? when I could just do that in the following line, however we are using a logger that will exit your program if any line exits with $? != 0, so the way we get around it is by using "./someCommand || rc=$?" which will exit with "0", but also give us the return code.
#default success code: rc=0 #run temptwo.sh in the background. If it fails, set rc=$? $(./temptwo.sh & || rc=$? ) #Trying to get the process id of "temptwo.sh" below (not sure if works) pid=$! #Wait until the process finishes wait $pid