I have a bash script which run a command to get its result and do something depends on the result. Here is the script:
#!/bin/bash
commandResult=$(($myCommand) 2>&1)
if [[ "$commandResult" == *Error* ]]; then
x="failed"
else
x="success"
fi
echo $x
exit 0;
There is no problem with this script, the issue is when I try to kill $myCommand
in the middle of running the script via kill -9 $myCommand
in command line, the $commandResult
will be null and the "success" will be printed.
How could I put the kill result in the $commandResult
or any other way to find out if process killed in this script?
Any help would be much appreciated.