While this document is primarily focused on writing shell scripts, there are a few helpful tips that can be useful to shell users and programmers alike. This section includes a few of those tips.
The alias Builtin
Entering Special Characters
Various Bourne shells also offer a number of other builtin commands that you may find useful, one of the more useful for command-line users being alias. This command allows you to assign a short name to replace a longer command. While this is not frequently used in shell scripts (unless you are intentionally trying to obfuscate your code), it is very convenient when using the shell interactively. For example:
alias listsource="ls *.c *.h" |
Typing the command listsource after entering this line will result in listing all of the .c and .h files in the current directory.
For more information, see the man page builtins, or for ZSH, zshbuiltins.
C Shell Note: The C shell syntax is similar, but not identical. In the C shell, the equals sign is replaced with a space. For example:
alias listsource "ls *.c *.h" |
Some shells treat tabs and other control characters in special ways. When writing a script in a text file, this is not generally an issue. However, when entering commands on the command line, it may get in the way if you need to enter these special characters as part of a command for some reason.
To enter a tab or other control character on the command line, type control-v followed by the tab key or other control character. The control-v tells the shell to treat whatever character comes next literally without interpreting it in any way during entry.
For example, to enter the ASCII bell character (control-G), you can type the following:
echo "control-V control-G" |
This will be seen on your screen as:
echo "^G" |
When you press return, your computer should beep.
Last updated: 2008-04-08