This section describes the many symbols peculiar to the C shell. The topics are arranged as follows:
Special files
Filename metacharacters
Quoting
Command forms
Redirection forms
~/.cshrc | Executed at each instance of shell invocation. |
~/.login | Executed by login shell after .cshrc at login. |
~/.logout | Executed by login shell at logout. |
~/.history | History list saved from previous login. |
/etc/passwd | Source of home directories for ~name abbreviations. (May come from NIS or NIS+ instead.) |
Metacharacter | Description |
---|---|
* | Match any string of zero or more characters. |
? | Match any single character. |
[abc...] | Match any one of the enclosed characters; a hyphen can be used to specify a range (e.g., a–z, A–Z, 0–9). |
{abc,xxx,...} | Expand each comma-separated string inside braces. The strings need not match actual filenames. |
~ | Home directory for the current user. |
~name | Home directory of user name. |
% ls new* Match new and new.1 % cat ch? Match ch9 but not ch10 % vi [D-R]* Match files that begin with uppercase D through R % ls {ch,app}? Expand, then match ch1, ch2, app1, app2 % mv info{,.old} Expands to mv info info.old % cd ~tom Change to tom's home directory
Quoting disables a character's special meaning and allows it to be used literally, as itself. The characters in the following table have special meaning to the C shell.
These characters can be used for quoting:
% echo 'Single quotes "protect" double quotes' Single quotes "protect" double quotes % echo "Don't double quotes protect single quotes too?" Don't double quotes protect single quotes too? % echo "You have `ls|wc -l` files in `pwd`" You have 43 files in /home/bob % echo The value of \$x is $x The value of $x is 100
cmd & | Execute cmd in background. |
cmd1 ; cmd2 | Command sequence; execute multiple cmd s on the same line. |
(cmd1 ; cmd2) | Subshell; treat cmd1 and cmd2 as a command group. |
cmd1 | cmd2 | Pipe; use output from cmd1 as input to cmd2. |
cmd1 ‘cmd2‘ | Command substitution; use cmd2 output as arguments to cmd1. |
cmd1 && cmd2 | AND; execute cmd1 and then (if cmd1 succeeds) cmd2. This is a “short-circuit” operation; cmd2 is never executed if cmd1 fails. |
cmd1 || cmd2 | OR; execute either cmd1 or (if cmd1 fails) cmd2. This is a “short-circuit” operation; cmd2 is never executed if cmd1 succeeds. |
% nroff file > file.out & Format in the background % cd; ls Execute sequentially % (date; who; pwd) > logfile All output is redirected % sort file | pr -3 | lp Sort file, page output, then print % vi `grep -l ifdef *.c` Edit files found by grep % egrep '(yes|no)' `cat list` Specify a list of files to search % grep XX file && lp file Print file if it contains the pattern, % grep XX file || echo XX not found otherwise, echo an error message
File Desciptor | Name | Common Abbreviation | Typical Default |
---|---|---|---|
0 | Standard input | stdin | Keyboard |
1 | Standard output | stdout | Terminal |
2 | Standard error | stderr | Terminal |
The usual input source or output destination can be changed, as seen in the following sections.
cmd >& file | Send both standard output and standard error to file. |
cmd >&! file | Same as above, even if noclobber is set. |
cmd >>& file | Append standard output and standard error to end of file. |
cmd >>&! file | Same as above, but append to or create file even if noclobber is set. |
cmd1 |& cmd2 | Pipe standard error together with standard output. |
(cmd > f1) >& f2 | Send standard output to file f1, standard error to file f2. |
cmd | tee files | Send output of cmd to standard output (usually the terminal) and to files. (See the Example in Chapter 2, under tee.) |
% cat part1 > book % cat part2 part3 >> book % mail tim < report % cc calc.c >& error_out % cc newcalc.c >&! error_out % grep Unix ch* |& pr % (find / -print > filelist) >& no_access % sed 's/^/XX /g' << "END_ARCHIVE" This is often how a shell archive is "wrapped", bundling text for distribution. You would normally run sed from a shell program, not from the command line. "END_ARCHIVE" XX This is often how a shell archive is "wrapped", XX bundling text for distribution. You would normally XX run sed from a shell program, not from the command line.
Copyright © 2003 O'Reilly & Associates. All rights reserved.