WEB*_*uju 2 command-line bash sleep for
我正在运行一个更大的单行命令。它意外地输出(每次迭代两次)以下内容:
__bp_preexec_invoke_exec "$_"
这是缩减命令(删除了循环中的其他活动):
for i in `seq 1 3`; do sleep .1 ; done
Run Code Online (Sandbox Code Playgroud)
注意:在我玩过几次之后,它莫名其妙地停止打印意外的输出
sleep .5
我不会得到意外的输出sleep .5
提示返回但没有输出__bp_preexec_invoke_exec
,但我无法确定它如何适用于我正在做的事情什么是__bp_preexec_invoke_exec "$_"?
如何在没有不需要的输出的情况下运行它?
这是输出 declare -f | grep preexec
preexec_functions+=(preexec);
__bp_preexec_interactive_mode="on"
__bp_preexec_invoke_exec ()
if [[ -z "$__bp_preexec_interactive_mode" ]]; then
__bp_preexec_interactive_mode="";
__bp_preexec_interactive_mode="";
local preexec_function;
local preexec_ret_value=0;
for preexec_function in "${preexec_functions[@]}";
if type -t "$preexec_function" > /dev/null; then
$preexec_function "$this_command";
preexec_ret_value="$?";
__bp_set_ret_value "$preexec_ret_value" "$__bp_last_argument_prev_command"
if [[ -z "${iterm2_ran_preexec:-}" ]]; then
__iterm2_preexec "";
iterm2_ran_preexec="";
__iterm2_preexec ()
iterm2_ran_preexec="yes";
Run Code Online (Sandbox Code Playgroud)
我在那里看到很多“iterm2”信息(我在 Mac 上使用 iTerm2.app)。
事实上,当我尝试使用 Terminal.app 进行重现时,我无法重现意外的输出。
出色的侦探declare -f
- 谢谢!
似乎__bp_preexec_invoke_exec
是https://github.com/rcaloras/bash-preexec/blob/master/bash-preexec.sh 的一部分。并且该脚本中似乎存在错误。
该项目通过添加 DEBUG 陷阱向 bash 添加了“preexec”功能,我没有测试,但我可以想象它可能无法按照您所看到的方式正常工作。检查它是否安装在您的环境中 - 您可以通过declare -f
. 似乎对于较新的 bash,您可以使用 PS0 而不是该项目,这可能会在没有问题的情况下执行相同的操作。