Title: File Descriptor Redirection
1File Descriptor Redirection
This is also useful for printing error messages
echo "Danger! Danger Will Robinson!" 2
Note I/O redirections are parsed in the order
they are encountered, from left to right. This
allows you to do fairly tricky things, including
throwing out standard output, and piping standard
output to a command.
2Functions
A function is defined using name ()
commands and is invoked like any other
command name args...
3Functions
You can redirect a function's I/O, embed it in
backquotes, etc., just like any other command.
Functions differ from external scripts ? the
shell does not spawn a subshell to execute them.
If you set a variable inside a function, the
new value will be visible outside of the
function. A function can use return n to
terminate with an exit status of n.
4Function Arguments
A function can take command-line arguments, just
like any script. Intuitively enough, these are
available through 1, 2... 9 just like the
main script.
5Useful Utilities
There are a number of commands that aren't part
of sh, but are often used inside sh scripts.
These include basename basename pathname
prints the last component of pathname basename
/foo/bar/baz prints baz
6Useful Utilities
dirname The complement of basename
dirname pathname prints all but the last
component of pathname, that is the directory
part pathname dirname /foo/bar/baz Prints
/foo/bar