On stackoverflow there are many solutions - how to close script by timeout or close script if there is an error. But how to have both approaches together? If during execution of the script there is an error - close script. If timeout is out - close script.
I have following code:
#!/usr/bin/env bash
set -e
finish_time=$1
echo "finish_time=" ${finish_time}
(./execute_something.sh) & pid=$!
sleep ${finish_time}
kill $pid
But if there is an error while execution - script still waits, when timeout would be out.