Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

Tips for Shell Users

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.

In this section:

The alias Builtin
Entering Special Characters


The alias Builtin

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"

Entering Special Characters

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.



< Previous PageNext Page > Hide TOC


Last updated: 2008-04-08




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice