Bourne shell idioms

Here are some portable Bourne shell idioms
that I find useful to remember for scripting.
The Bourne shell does much more than most
users realize, and the ksh and bash
extensions are rarely essential. (From the
command-line, bash and ksh are vastly more
useful.)

For example, you can edit a bash command by default
in emacs mode. Change to vi with

set -o vi

In emacs mode, you can edit your command in
your environmental $EDITOR with cntl-x
cntl-e

In vi-mode, use esc-v. See help fc
for more.

Repeat the last argument of the previous
command with !$. Repeat all arguments
without the command with !*.

To guarantee that a background process
outlives the current shell, add extra
parentheses like this:

( command & )

Otherwise, your current shell, by exiting X
or ssh, may terminate all processes that have
your shell as the parent process. The extra
parentheses starts a subshell that exits as
soon as the command is spawned in the
background. The background process changes
its parent process ID to 1. This is a
command-line version of the "double fork."