我需要在 shell 开始执行用户传递的命令之前执行一个命令,我尝试使用带有 DEBUG 信号的陷阱,但那没有发生。
我已经在/etc/profile 中注册了陷阱。
trap 'echo "my_command"' DEBUG
现在发生的事情是:
sw0:root:root> pwd
/root
my_command
sw0:root:root>
我想要的是:
sw0:root:root> pwd
my_command
/root
sw0:root:root>
使用的 Bash 版本:
GNU bash, version 2.04.0(1)-release (powerpc-unknown-linux-gnu)
我希望我的命令在用户在 shell 中输入的每个命令之前执行,我该怎么做?
请帮我解决这个问题,我尝试了很多谷歌搜索,但没有帮助。
最佳答案
您可能正在寻找类似 PROMPT_COMMAND
的内容:
The contents of this variable are executed as a regular Bash command just before Bash displays a prompt.
关于linux - 如何让shell在每个用户输入命令之前执行命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29772973/