2.19. Alias

An alternative to functions and separate scripts for very simple things is the alias command.

This command creates an alias, or alternate name for another command.

Aliases are supported by both Bourne and C shell families, albeit with a slightly different syntax.

They are most often used to create simple shortcuts for common commands.

In Bourne shell and derivatives, the new alias is followed by an '='. Any command containing white space must be enclosed in quotes, or the white space must be escaped with a \.

#!/bin/sh

alias dir='ls -als'

dir
	

C shell family shells use white space instead of an '=' and do not require quotes around commands containing white space.

#!/bin/csh

alias dir ls -als

dir
	

An alias can contain multiple commands, but in this case it must be enclosed in quotes, even in C shell.

#!/bin/csh

# This will not work:
# alias pause printf "Press return to continue..."; $<
#
# It is the same as:
#
# alias pause printf "Press return to continue..."
# $<

# This works
alias pause 'printf "Press return to continue..."; $<'

pause