Variables
These are portably defined with a:
name=valuecommand outside of a listlists context.These may also be defined with some builtins such as
export,set,readonlyin some cases.Functions
These are portably defined with:
name() compound command <>optionalcompound_command redirect<>any_redirectscommand in command position.The shell is specified not to expand or interpret any portion of the function definition it might find in the command at definition time.
- This prohibition does not include aliases, though, as these are expanded during the parsing process of a shell's command read, and so
aliasvalues, if thealiasis found in correct context, are expanded into the function definition command when found.
- This prohibition does not include aliases, though, as these are expanded during the parsing process of a shell's command read, and so
As mentioned, the shell saves the parsed value of the definition command as a static string in its memory, and it performs all expansions and redirections found within the string only when the function name is later found post-parse as called.
Aliases
These are portably defined as arguments to the
aliasbuiltin with a:alias name=valuecommand.in command positionLike functions,
aliasdefinitions are interpreted when the definition names are later found in command position.Unlike functions, though, as their definitions are arguments to the
aliascommand, valid shell expansions found within are also interpreted at define time. And soaliasdefinitions are always twice interpreted.Also unlike functions,
aliasdefinitions are not parsed at all at define time, but, rather, it is the shell's parser that expands their values pre-parse into a command string when they are found.