5/31/2023 0 Comments Trap quest debug![]() For example, using the setup above: ~/Scratch $ echo 1 echo 2 ![]() Then Bash will execute echo Bye before it prints each subsequent prompt (i.e., after it has finished executing the previous command line). The idea behind PROMPT_COMMAND is also very simple: if you run PROMPT_COMMAND="echo Bye" What if we only want to run a command once per composite command, like the preexec hook in zsh? ![]() ~/Scratch $ if then echo "/etc/passwd exists" fi For example, using the setup above: ~/Scratch $ echo 1 & echo 2 echo 3 For example: ~/Scratch $ lsĪ caveat, however, is that the DEBUG trap is triggered once per simple command if you have command lists or control structures, the trap will be triggered multiple times. Then Bash will run echo Hello before it executes each subsequent command. The idea is pretty straightforward: if you run trap "echo Hello" DEBUG The DEBUG trap is an extremely handy feature of Bash. This patch will likely be merged into Bash 4.4. Update : A patch by Dan Stromberg adds a PS0 variable to Bash that greatly simplifies what’s described in this article.
0 Comments
Leave a Reply. |