linux - 如何让shell在每个用户输入命令之前执行命令

标签 linux bash shell

我需要在 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/

相关文章:

linux - 设备驱动程序 IOCTL 传递 int

无法使用文件描述符通过 fstat() 或 lseek() 获取文件大小

linux - 在 Linux 中 : How can I create a symbolic link to a file whose name starts with a dash/minus sign ?

python - 批处理 : GNU-make, Snakemake 还是什么?

mysql - Bash + MySQL -d 反引号问题

linux - 从 bash 脚本中的 grep 输出扩展环境变量

Java 和 Bash shell

linux - 如何将 bash 脚本的执行限制为特定用户

linux - 定义带或不带导出的变量

c - 我正在 build 一个小 shell 。如何将两个进程的标准输入和输出设置为管道,以便它们可以通信?