Suppress signal occurrence

Viewed 148

I have a bash script similar to this:

#!/bin/bash
timeout -s ALRM 1 sleep 5

This script should trigger the timeout and return with an exit code of 124. It does, however it also prints the following text to stderr:

a.sh: line 2:   604 Alarm clock             timeout -s ALRM 1 sleep 5

The bash version is

bash --version
GNU bash, version 5.0.18(1)-release (arm-mut-linux-gnueabi)

What is causing this debug output? How do I supress it?

Here's a list of my shopt

# shopt
autocd          off
assoc_expand_once       off
cdable_vars     off
cdspell         off
checkhash       off
checkjobs       off
checkwinsize    on
cmdhist         on
compat31        off
compat32        off
compat40        off
compat41        off
compat42        off
compat43        off
compat44        off
complete_fullquote      on
direxpand       off
dirspell        off
dotglob         off
execfail        off
expand_aliases  on
extdebug        off
extglob         off
extquote        on
failglob        off
force_fignore   on
globasciiranges on
globstar        off
gnu_errfmt      off
histappend      off
histreedit      off
histverify      off
hostcomplete    on
huponexit       off
inherit_errexit off
interactive_comments    on
lastpipe        off
lithist         off
localvar_inherit        off
localvar_unset  off
login_shell     off
mailwarn        off
no_empty_cmd_completion off
nocaseglob      off
nocasematch     off
nullglob        off
progcomp        on
progcomp_alias  off
promptvars      on
restricted_shell        off
shift_verbose   off
sourcepath      on
xpg_echo        off
1 Answers

Seems like on your system, Busybox's timeout comes first in $PATH.

On my Debian Linux:

[STEP 101] $ cat foo.sh
busybox timeout -s ALRM 1 sleep 5
echo rc=$?
/usr/bin/timeout -s ALRM 1 sleep 5
echo rc=$?
[STEP 102] $ bash foo.sh
foo.sh: line 1: 86649 Alarm clock             busybox timeout -s ALRM 1 sleep 5
rc=142
rc=124
[STEP 103] $

To suppress the Alarm clock message you can

{ timeout ...; } 2> /dev/null

Regarding the Alarm clock message I tried some common signals:

[STEP 104] $ cat bar.sh
for sig in INT QUIT TERM PIPE KILL SEGV HUP ALRM USR1; do
    sleep 1 &
    echo - $sig
    kill -$sig %%
    wait
done
[STEP 105] $ bash bar.sh
- INT
- QUIT
- TERM
- PIPE
- KILL
bar.sh: line 5: 86934 Killed                  sleep 1
- SEGV
bar.sh: line 5: 86935 Segmentation fault      sleep 1
- HUP
bar.sh: line 5: 86936 Hangup                  sleep 1
- ALRM
bar.sh: line 5: 86937 Alarm clock             sleep 1
- USR1
bar.sh: line 5: 86938 User defined signal 1   sleep 1
[STEP 106] $
Related