Simple:
a="echo -e 'a\nb' | wc -l"eval timeout 10 $a
Output:
2
This will work
if timeout "$PROGRAM" "$OPT1" "$OPT2" ... ; then echo Program ran successfullyelse echo Program terminated due to timeoutfi
If it's about keeping commands in variables, this will work, although don't know if it's a 'proper bash way' to do it:
command.sh:
#!/bin/bashecho -e 'a\nb' | wc -l
run.sh:
#!/bin/basha="command.sh"timeout 10 ./$a