在使用 emacs 编辑 bash shell 脚本 (#!/bin/sh( 时,每当我尝试输入"<<<"时,在第三个括号中,它会将"EOF"直接放在括号后面,并在行尾放置两个回车符,然后再次写"EOF",如下所示:
resiline=$(grep -w -n "$searchstring" input/*)
resifile=$(cut -d : -f 1 <<<EOF $resiline)
EOF
它为什么要这样做,我如何防止它这样做?
它这样做是因为启用了sh-electric-here-document-mode
。 要以交互方式禁用它,只需执行 M-x sh-electric-here-document-mode
.
在 Emacs 24 中,默认情况下sh-mode
启用此次要模式,但您可以使用sh-mode-hook
再次禁用它。
在 Emacs 25 中,sh-mode-hook
默认包含sh-electric-here-document-mode
(而不是sh-mode
直接调用它(,因此您可以通过以下方式删除它:
M-x customize-option
RET sh-mode-hook
RET