bash: Aliases

1 
1 6.6 Aliases
1 ===========
1 
1 ALIASES allow a string to be substituted for a word when it is used as
1 the first word of a simple command.  The shell maintains a list of
1 aliases that may be set and unset with the 'alias' and 'unalias' builtin
1 commands.
1 
1    The first word of each simple command, if unquoted, is checked to see
1 if it has an alias.  If so, that word is replaced by the text of the
1 alias.  The characters '/', '$', '`', '=' and any of the shell
1 metacharacters or quoting characters listed above may not appear in an
1 alias name.  The replacement text may contain any valid shell input,
1 including shell metacharacters.  The first word of the replacement text
1 is tested for aliases, but a word that is identical to an alias being
1 expanded is not expanded a second time.  This means that one may alias
1 'ls' to '"ls -F"', for instance, and Bash does not try to recursively
1 expand the replacement text.  If the last character of the alias value
1 is a BLANK, then the next command word following the alias is also
1 checked for alias expansion.
1 
1    Aliases are created and listed with the 'alias' command, and removed
1 with the 'unalias' command.
1 
1    There is no mechanism for using arguments in the replacement text, as
1 in 'csh'.  If arguments are needed, a shell function should be used
1 (⇒Shell Functions).
1 
1    Aliases are not expanded when the shell is not interactive, unless
11 the 'expand_aliases' shell option is set using 'shopt' (⇒The Shopt
 Builtin).
1 
1    The rules concerning the definition and use of aliases are somewhat
1 confusing.  Bash always reads at least one complete line of input before
1 executing any of the commands on that line.  Aliases are expanded when a
1 command is read, not when it is executed.  Therefore, an alias
1 definition appearing on the same line as another command does not take
1 effect until the next line of input is read.  The commands following the
1 alias definition on that line are not affected by the new alias.  This
1 behavior is also an issue when functions are executed.  Aliases are
1 expanded when a function definition is read, not when the function is
1 executed, because a function definition is itself a command.  As a
1 consequence, aliases defined in a function are not available until after
1 that function is executed.  To be safe, always put alias definitions on
1 a separate line, and do not use 'alias' in compound commands.
1 
1    For almost every purpose, shell functions are preferred over aliases.
1