Home Check if timeout command was successful
 I am trying to run a command in a bash file and put the output of command in a variable. But the command must NOT take longer than 2 seconds. I use the command: timeout -k 2 2 ls /var/log/;  And there is no problem. The command either list the contents of log directory or kills the command in case it took more than two seconds. But when I try to put the output in a variable the commands hangs and doesn't reply or get killed! I use like this: result=$(timeout -k 2 2 ls /var/log/);  Where is my mistake? Javier Elices 2# Javier Elices Reply to 2018-02-13 17:24:21Z  The timeout command will exit with status 124 if it had to kill the process; see here. So you may try something like: timeout -k 2 2 ls /var/log/ >directory.txt if [$? -eq 124 ] then echo "Timeout exceeded!" else cat directory.txt fi