
我經常同時登入多個 SSH 會話。要從多個會話註銷,我按CTRL+ d,直到回到本機。
但是,有時我按太多次,我的終端就會退出。
有沒有辦法讓CTRL+d無法關閉我的終端機?
我正在使用終結者作為我的終端模擬器。
答案1
您也可以在 bash 中停用 eof:
set -o ignoreeof
答案2
您可以IGNOREEOF
在 bash 中使用環境變數。因此,在它真正退出 shell 之前export IGNOREEOF=42
,您必須按Ctrl+D
四十二次。
POSIX也set
有-o ignoreeof
設定。
答案3
Ctrl-D EOF 字元由 shell 解釋,而不是由終端模擬器專門解釋。其他答案已經涵蓋了 bash 設置,儘管其他 shell 有所不同。
對於 C-shell(例如 tcsh),您可以將其新增至 tcshrc 檔案:
# Prevent accidental logouts completely
set ignoreeof
# Just prevent the first two, and allow the third
set ignoreeof=3
對於 Fish shell,Ctrl-D 行為由鍵綁定控制。預設為delete-or-exit
,因此您可以將 的鍵綁定設定為\cd
僅delete-char
支援刪除。
更多詳細資訊請參見魚Github問題(例如,在3.0之前的版本中,您需要將 新增bind
至名為 的函數中fish_user_key_bindings
,在3.0之後,您可以將其放入 中~/.config/fish/config.fish
)但總結一下:
bind \cd delete-char # Don't exit on accidental Ctrl-D
bind \cd\cd\cd delete-or-exit # Exit on the third one