------------------------ Week 5 Notes for NET2003 ------------------------ -Ian! D. Allen - idallen@idallen.ca Remember - knowing how to find out an answer is more important than memorizing the answer. Learn to fish! RTFM! (Read The Fine Manual) Keep up on your readings (Course Outline: average 5 hours/week) Standard Output and Standard Error Notes: redirection.txt Notes: stdxxx.c++.txt - sample C++ program using cout/cerr Two default kinds of output stream for Unix programs: - Unix "unit 1": same as cout/stdout in C programming $ command 1>file $ command >file - Unix "unit 2": same as cerr/stderr in C programming $ command 2>file $ touch foo $ ls -l foo nosuchfile 1>out 2>errors - to redirect both units, must use: 2>&1 not >out 2>out - scripts: issuing error messages: echo 1>&2 "$0: error msg" Throwing away output to /dev/null $ ls -l date nosuchfile 2>/dev/null $ ls -l date nosuchfile >/dev/null Standard Unix command-line mail program: Without arguments, reads your Unix mail file and prompts for commands: $ mail & ? # <- ? gives a short list of some useful commands & x # <- quit without changing mailbox & q # <- quit and empty mailbox into "$HOME/mbox" With one or more arguments, sends email to those userids by reading stdin: $ mail idallen@idallen.ca idallen@idallen.net Subject: this is a test This is what I want to say. ^D Cc: idallen@hotmail.com You can also use a single period instead of EOF to end the input. If mail is not reading a terminal, it doesn't prompt for a subject. (You can supply one using a command-line option.) $ echo "this is a one line email" | mail idallen@idallen.org $ mail idallen@idallen.ca out $ less out Command "wget" fetches raw web pages and saves them locally (unformatted): $ wget -O out http://idallen.com/ $ less out Translating or deleting individual characters: tr "tr" is one of the very few Unix commands that *only* reads stdin (it cannot accept pathnames on the command line) To change words and strings, you need to learn to use "sed", not "tr". Translate all colon characters to blanks from the password file: $ wc -w