作者:dvs5453401 | 来源:互联网 | 2023-09-16 17:36
我有一个类似于此的 bash 脚本:
#!/bin/bash
timeout -s ALRM 1 sleep 5
此脚本应触发超时并返回退出代码 124。但它也会将以下文本打印到 stderr:
a.sh: line 2: 604 Alarm clock timeout -s ALRM 1 sleep 5
bash 版本是
bash --version
GNU bash,版本 5.0.18(1)-release (arm-mut-linux-gnueabi)
是什么导致此调试输出?我如何压制它?
这是我的商店列表
# 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
回答
似乎在您的系统上,Busyboxtimeout
在$PATH
.
在我的 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] $
要抑制Alarm clock
消息,您可以
{ timeout ...; } 2> /dev/null
{ timeout ...; } 2> /dev/null
关于Alarm clock
消息,我尝试了一些常见的信号: