gpt4 book ai didi

bash - 抑制信号发生

转载 作者:行者123 更新时间:2023-12-03 21:06:55 27 4
gpt4 key购买 nike

我有一个类似于此的 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, version 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

最佳答案

好像在你的系统上,Busybox 的 timeout排在第一位 $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

关于 Alarm clock消息我尝试了一些常见的信号:
[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] $

关于bash - 抑制信号发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66329317/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com