Download ${Unix_Tools} - The Computer Laboratory

Transcript
Basic shell syntax – sequences
Execute several commands (or entire pipes) in sequence:
$ command1 ; command2 ; command3
For example:
$ date ; host ryath.ds.cam.ac.uk
Thu Oct 31 11:48:22 GMT 2013
ryath.ds.cam.ac.uk has address 131.111.8.223
Conditional execution depending on success of previous command
(as in logic-expression short-cut):
$ make ftest && ./ftest
$ ./ftest || echo 'Test failed!'
Return value 0 for success is interpreted as Boolean value “true”, other return values for problems
or failure as “false”. The trivial tools true and false simply return 0 and 1, respectively.
17
File redirecting – basics
Send stdout to file
$ command >filename
Append stdout to file
$ command >>filename
Send both stdout and stderr to the same file. First redirect stdout to
filename, then redirect stderr (file descriptor 2) to where stdout goes
(target of file descriptor 1 = &1):
$ command >filename 2>&1
Feed stdin from file
$ command <filename
18