Hook function before a command is executed

This function is executed right before a command is executed by the shell. It’s called with three parameters which describe the command to be executed.

Usage

1st argument
(required)
If the history mechanism is active, then this is the string the user typed. Otherwise it’s an empty string.
2nd argument
(required)
The size-limited, single-line value of the executed command.
3rd argument
(required)
Full text of the command which is going to be executed.

Examples

Log executed commands
1
2
preexec() { echo "Command to be executed: $3" >&2; }
echo hello $LOGNAME                                                                                                  ~
Output:
1
2
Command to be executed: echo hello $LOGNAME
hello user1
BashSupport Pro 是一款支持 preexec** 的 **Zsh 集成开发环境 - 立即试用
© 2020–2025 Joachim Ansorg
声明
隐私政策
许可条款