I am using Emacs on a LINUX system that uses Portable Batch System (PBS) for controlling the use of resources. The PBS scripts require "#PBS -S /bin/..." as the first line in the script to declare the shell of the script to PBS. When I load the script into Emacs, there is no #!/bin/... to alert Emacs to which shell is being programmed. So, how can I get the shell-script-mode in Emacs to intepret #PBS -S /bin/bash to be a bash shell code?


Add this to your .emacs:

(setq auto-mode-interpreter-regexp 
    "#\\(?:!\\|PBS -S \\)[ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)")

That makes Emacs consider #PBS -S as an alternative to the #! prefix.

| improve this answer | |

Add something like the following to the end of the file:

# Local Variables:
# mode: shell-script
# End: 

Of course, there are other ways, such as a distinct naming pattern used for setting the variable auto-mode-alist.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.