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?