The following sections list the set of variables and special characters supported by both csh and sh.

Predefined Environment Variables

Name Meaning
$HOME The full pathname of your home directory
$PATH A list of directories to search for commands
$MAIL The full pathname of your mailbox
$USER Your username
$SHELL The full pathname of your login shell
$TERM The type of your terminal

Predefined Local Variables

Name Value
$0 The name of the shell script
$n n is a number ranges from 1 to 9. $n refers to the nth command-line argument
$* A list of all command-line arguments

Metacharacters

Some characters are processed specially by the shell; these are known as metacharacters and you have been using them in writing csh and sh scripts. Examples of these characters are the wildcard character *, the redirection characters >> and <, and the pound sign #. The following table lists the metacharacters common to both csh and sh:

Metacharacter Meaning
> Output redirection; writes standard output to a file
>> Output redirection; appends standard output to a file
< Input redirection; reads standard input from a file
`command` Command substitution; replaced by the output from command
| Pipe symbol; sends the output of one process to the input of another
# If appears on the first line, following it is the pathname of the shell. If appears on any other line, all characters that follow up to a new line are treated as comments by the shell
$ Expands the value of a variable

The following wildcards are supported by both csh and sh:

Wildcard Meaning
* Matches any string, including the empty string
? Matches any single character
[start-end] Matches any character in the range specified by start and end
[xy] Matches any character or string that starts with the character specified by x or y

Quoting

The single quotes and double quotes have the same functions in both csh and sh:

Termination and Exit Codes

Commands executed in either csh or sh always return an exit status. An exit value of 0 indicates the command has completed successfully, and a nonzero exit value indicates failure. All built-in commands (e.g., ls, cd) return an exit value of 1 if they fail. The exit value of a command is stored in a predefined variable. Note that in csh, this variable is $status, and in sh, this variable is $?.