Emacs and. sh (or. bash)?

﹥>﹥吖頭↗ 提交于 2021-02-10 06:19:32

问题


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

  1. look at the shebang #!/usr/bin/env bash line
  2. Match the file extension to a major mode according to your auto-mode-alist configuration. You can set bash as the default shell to use by configuring sh-alias-alist, eg. (cl-pushnew '(sh . bash) sh-alias-alist :test #'equal) in your shell config file.
  3. Using a local variable, eg. as the first line of a script: # -*- sh; sh-shell: bash; -*- to tell emacs the major mode is sh and to use the bash shell.
  4. 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 the sh-script function sh-set-shell.


来源:https://stackoverflow.com/questions/55230845/emacs-and-sh-or-bash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!