Function: sh-mode

Major mode for editing shell scripts.
This mode works for many shells, since they all have roughly the same syntax,
as far as commands, arguments, variables, pipes, comments etc. are concerned.
Unless the file's magic number indicates the shell, your usual shell is
assumed. Since filenames rarely give a clue, they are not further analyzed.

This mode adapts to the variations between shells (see `sh-set-shell') by
means of an inheritance based feature lookup (see `sh-feature'). This
mechanism applies to all variables (including skeletons) that pertain to
shell-specific features.

The default style of this mode is that of Rosenblatt's Korn shell book.
The syntax of the statements varies with the shell being used. The
following commands are available, based on the current shell's syntax:

C-c C-c case statement
C-c C-f for loop
C-c ( function definition
C-c TAB if statement
C-c C-l indexed loop from 1 to n
C-c C-o while getopts loop
C-c C-r repeat loop
C-c C-s select loop
C-c C-u until loop
C-c C-w while loop

For sh and rc shells indentation commands are:
C-c ? Show the variable controlling this line's indentation.
C-c = Set then variable controlling this line's indentation.
C-c < Change the indentation variable so this line
would indent to the way it currently is.
C-c > Set the indentation variables so the
buffer indents as it currently is indented.


DEL Delete backward one position, even if it was a tab.
C-j Delete unquoted space and indent new line same as this one.
M-e Go to end of successive commands.
M-a Go to beginning of successive commands.
C-c : Set this buffer's shell, and maybe its magic number.
C-M-x Have optional header and region be executed in a subshell.

`sh-electric-here-document-mode' controls whether insertion of two
unquoted < insert a here document.

If you generally program a shell different from your login shell you can
set `sh-shell-file' accordingly. If your shell's file name doesn't correctly
indicate what shell it is use `sh-alias-alist' to translate.

If your shell gives error messages with line numbers, you can use C-c C-x
with your script for an edit-interpret-debug cycle. In addition to any hooks its parent mode `prog-mode' might have run, this mode runs the hook `sh-mode-hook', as the final step during initialization.