必要な場合にのみ削除を検討してください。

必要な場合にのみ削除を検討してください。

clear端末に特定のコマンドを入力するたびに(実行する前に)、特定のコマンドを実行するようにbashを設定したいと思います。どうすればいいですか?

私はDebian Linuxを使用しています。

ベストアンサー1

Bashには事前コマンドフックがあります。一種の。

preexec () {
  clear
}
preexec_invoke_exec () {
    [ -n "$COMP_LINE" ] && return                     # do nothing if completing
    [ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return # don't cause a preexec for $PROMPT_COMMAND
    local this_command=`history 1 | sed -e "s/^[ ]*[0-9]*[ ]*//g"`; # obtain the command from the history, removing the history number at the beginning
    preexec "$this_command"
}
trap 'preexec_invoke_exec' DEBUG

おすすめ記事