CS 114 - Unix Tools - Fall 2004
Assignment 4 - Frequently Answered Answers
Here are some answers to some frequently asked questions.
- Don't forget #!/bin/sh and to chmod +x your script.
- Quote your variables with double quotes.
- sed reads from stdin and writes to stdout.
You need to pass the old file name to sed so that it can read
it from stdin. Use a pipe (|).
- Use backquotes to capture the output of a program. The shell
will substitute the output of cmd for `cmd`
- The backquote key is usually to the left of the 1.
- The sed expression is in $1. The files are in $2, $3, ...
Save the sed expression in a variable and use shift to get the file anmes
into $1, $2, ...
-
"$@" is equivalent to "$1" "$2" "$3" ... Try using a for loop over "$@".
- $? contains the exit status of the last command
executed.
- Use exit 1 to exit your script after reporting an error.
- Tilde.