I am fiddling with Linux command "timeout": it simply stops a long running command after a given seconds. But I would like to timeout not only a command, but a group of commands. I can group command in two way ( ) and { ;} however none of the following works:
timeout 1 { sleep 2; echo something; }
timeout 1 ( sleep 2; echo something )
How can I do that with grouping?
You can also use the Here Document EOF method to create the multi-line script on the fly. The main advantage of it, is that you can use double quotes without escaping it:
timeout 1s bash <<EOF
sleep 2s
echo "something without escaping double quotes"
EOF
Notes:
export -f my_func
or set -o allexport
for all functions (before declaring them). This is relevant for previous answers as well, since calling bash/sh run the process in new session, unaware to local environment functions.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With