问题
I've tried finding an Emacs specific answer to this one, so apologies if it is repetitive. Simple question. I know that from the point of view of the interpreter it doesn't matter if you write a bash script with or without the .sh or. bash suffix, but does using one of either of these change the way in which Emacs treats the file when editing it? I've been playing around with some bash scripts in Emacs, and I've half answered my question. But I'm brand new to bash, so a lot is still unclear.
Thanks :)
wds
PS. I've asked this question in my programming class but to no avail.
回答1:
Various ways emacs can determine the major-mode
and shell type
- look at the shebang
#!/usr/bin/env bash
line - Match the file extension to a major mode according to your
auto-mode-alist
configuration. You can setbash
as the default shell to use by configuringsh-alias-alist
, eg.(cl-pushnew '(sh . bash) sh-alias-alist :test #'equal)
in your shell config file. - Using a local variable, eg. as the first line of a script:
# -*- sh; sh-shell: bash; -*-
to tell emacs the major mode issh
and to use thebash
shell. - Set the major mode interactively with M-x sh-mode and set the type of shell by setting the local
sh-shell
variable or using the thesh-script
functionsh-set-shell
.
来源:https://stackoverflow.com/questions/55230845/emacs-and-sh-or-bash