| 1 | #!/bin/bash |
| 2 | # Changes a file to all uppercase. |
| 3 | |
| 4 | E_BADARGS=85 |
| 5 | |
| 6 | if [ -z "$1" ] # Standard check for command-line arg. |
| 7 | then |
| 8 | echo "Usage: `basename $0` filename" |
| 9 | exit $E_BADARGS |
| 10 | fi |
| 11 | |
| 12 | tr a-z A-Z <"$1" |
| 13 | |
| 14 | # Same effect as above, but using POSIX character set notation: |
| 15 | # tr '[:lower:]' '[:upper:]' <"$1" |
| 16 | # Thanks, S.C. |
| 17 | |
| 18 | # Or even . . . |
| 19 | # cat "$1" | tr a-z A-Z |
| 20 | # Or dozens of other ways . . . |
| 21 | |
| 22 | exit 0 |
| 23 | |
| 24 | # Exercise: |
| 25 | # Rewrite this script to give the option of changing a file |
| 26 | #+ to *either* upper or lowercase. |
| 27 | # Hint: Use either the "case" or "select" command. |