0

I'm trying to get Emacs to understand that my script is bash.

I tried adding -*- bash -*- to the first line of the file, but it still opens in Shell-script[sh] mode. I can rename the file to give it a bash extension (currently it's .sh) but this might break some existing code.

Is there some way to give Emacs this hint?

Stefan
  • 26,154
  • 3
  • 46
  • 84
Shep
  • 103
  • 2

1 Answers1

2

C-h m should tell you:

[...]
shell-specific features.  Shell script files can use the `sh-shell' local
variable to indicate the shell variant to be used for the file.
[...]

so adding -*- sh-shell: bash -*- on the first line should do the trick.

Stefan
  • 26,154
  • 3
  • 46
  • 84
  • `auto-mode-alist` should be mentioned here. `C-h v` `auto-mode-alist` – Muihlinn Jun 03 '20 at 05:52
  • I'm not sure this is the right answer. Is the shebang line (`#!/bin/bash`) not sufficient? Either way I think it should be added on the *second* line. – jagrg Jun 03 '20 at 13:25
  • @jagrg: Indeed the shebang line can do the trick. My answer presumes we're talking about a file without the shebang line. – Stefan Jun 03 '20 at 16:44