How to run some command before or after every Bash command entered from console?

后端 未结 2 1655
情书的邮戳
情书的邮戳 2020-11-29 06:03

I want to run a command, for example

echo \"foobar\";

After each command, entered by the user.

Two scenarios:

  • When th
2条回答
  •  醉酒成梦
    2020-11-29 06:27

    As l0b0 suggests, you can use PROMPT_COMMAND to do your second request and you won't have to touch PS1.

    To do your first request, you can trap the DEBUG pseudo-signal:

    trap 'echo "foobar"' DEBUG
    

提交回复
热议问题