ShMode

Shell Script mode, ‘sh-mode’, is the major mode for editing Unix and GNU/Linux shell script code. It was originally authored by DanielPfeiffer

It supports several shell variants, including bash, csh, ksh and zsh, as well as plain Bourne shell, sh.

See ShellMode, for using the shell interactively.

See DosMode, for editing Dos scripts (batch files).

Icicles Enhancements to Shell Script Mode

In Shell Script mode, command ‘complete-tag’ is remapped to ‘comint-dynamic-complete’, so the latter is bound to the keys that would normally be bound to the former. This is the vanilla Emacs behavior.

Icicle mode remaps ‘comint-dynamic-complete’ (hence the same keys) in Shell Script mode to a similar command that uses Icicles completion whenever there are multiple completion candidates. This means that you can cycle to choose a candidate, complete using one or more substrings or regexps (progressive completion), and so on. See Icicles - Completion in Comint Modes.

Other Extensions to Shell Script Mode

Q&A

Q: There should be a manner to send commands to an inferior ShellMode buffer.

A: Try

  (process-send-string (current-buffer) "echo Merry X-mas!\n")

Q: Generally, how does one customize sh-mode? Specifically, when I type if [ ... ] and hit return, it indents. I want to disable this behavior, and only auto-indent to the indentation of the previous line (which in this case is zero). I’m using GNU Emacs 24.4.1.

Q: Problem with bash - quoted command substitution

GNU Emacs 24.5.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21)

# this is OK
LINK=$(echo $PROFILE | awk -F\; '{print $2}' | sed 's/\ /\-/g' | sed 's/"//g' | sed 's/^/cdi-profile-/g')

# quoting the above throws off the mode
# in particular, causes lines following this one to be treated as strings
LINK="$(echo $PROFILE | awk -F\; '{print $2}' | sed 's/\ /\-/g' | sed 's/"//g' | sed 's/^/cdi-profile-/g')"

CategoryShell