# Aliases apply to the command word, at parse time. alias hi='echo hello' hi there alias alias hi alias nothere; echo "status=$?" # An alias is not expanded inside its own text. alias echo='echo E:' echo x unalias echo echo y # A value ending in a blank makes the next word eligible too. alias run='command ' two='echo 2' run two # After an assignment the command word is still an alias candidate. X=1 hi again # Quoting any part of the word prevents expansion. \hi 2>/dev/null; echo "quoted=$?" 'hi' 2>/dev/null; echo "quoted=$?" # Aliases can produce reserved words and whole constructs. alias loop='for i in 1 2; do' fin='done' loop echo $i; fin alias both='echo a; echo b' both # Only the command position: an argument is left alone. echo hi # Defined on one line, usable from the next; in a function body the alias # is expanded when the function is read. alias later='echo later-1' f() { later; } alias later='echo later-2' f later type hi; command -v hi unalias -a; alias | wc -l | tr -d ' ' unalias nope; echo "status=$?" alias 'bad name=x'; echo "status=$?" alias multi='echo m1 echo m2' multi alias empty='' empty empty echo after-empty eval 'alias ev="echo from-eval"' ev alias hi='echo hello' x=$(hi sub); echo "$x"