09.06.2013 Views

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>XENIX</strong> Programming csh: C Shell<br />

the C shell translates this to<br />

Is -s /usr/bill<br />

Note that the tilde (-) is a special C shell symbol that represents the user's home<br />

directory.<br />

Thus the alias command can be used to provide short names for commands, to provide<br />

default arguments, and to define new short commands in terms of other commands. You<br />

can also define aliases that contain multiple commands or pipelines, showing where the<br />

arguments to the original command are to be substituted using the facilities of the<br />

history mechanism. Thus the definition<br />

alias cd 'cd \!* ; Is '<br />

specifies an Is command after each cd command. We enclosed the entire alias definition<br />

in single quotation marks (') to prevent most substitutions from occurring and to prevent<br />

the semicolon (;) from being recognized as a metacharacter. The exclamation mark (!)<br />

is escaped with a backslash (\) to prevent it from being interpreted when the alias<br />

command is typed in. The "\!*" here substitutes the entire argument list to the<br />

prealiasing cd com mand; no error is given if there are no arguments. The semicolon<br />

separating commands is used here to indicate that one command is to be done and then<br />

the next. Similarly, the following example defines a command that looks up its first<br />

argument in the password file.<br />

alias whois 'grep \! " /e<strong>tc</strong>/passwd'<br />

The C shell reads the .cshrc file each time it starts up. If you place a large number of<br />

aliases there, C shells will tend to start slowly. You should try to limit the number of<br />

aliases you have to a reasonable number (10 or 15). Having too many aliases causes<br />

delays and makes the system seem sluggish when you execute commands from within an<br />

editor or other programs.<br />

Redirecting Input and Output<br />

In addition to the standard output, commands also have a standard error output that is<br />

normally directed to the terminal even when the standard output is redirected to a file<br />

or a pipe. It is occasionally useful to redirect the standard error output along with the<br />

standard output. For instance, if you want to redirect the output of a long-running<br />

command into a file and wish to have a record of any error message it produces, you can<br />

type<br />

command >& file<br />

The ">&" here tells the C shell to route both the standard error output and the standard<br />

output into file. Similarly, you can give a command of the form<br />

command I& lpr<br />

to route both standard output and standard error output through the pipe to the line<br />

printer.<br />

8-7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!