| 1 | #!/bin/bash |
| 2 | |
| 3 | # delete.sh, a not-so-cunning file deletion utility. |
| 4 | # Usage: delete filename |
| 5 | |
| 6 | E_BADARGS=85 |
| 7 | |
| 8 | if [ -z "$1" ] |
| 9 | then |
| 10 | echo "Usage: `basename $0` filename" |
| 11 | exit $E_BADARGS # No arg? Bail out. |
| 12 | else |
| 13 | file=$1 # Set filename. |
| 14 | fi |
| 15 | |
| 16 | |
| 17 | [ ! -f "$file" ] && echo "File \"$file\" not found. \ |
| 18 | Cowardly refusing to delete a nonexistent file." |
| 19 | # AND LIST, to give error message if file not present. |
| 20 | # Note echo message continuing on to a second line after an escape. |
| 21 | |
| 22 | [ ! -f "$file" ] || (rm -f $file; echo "File \"$file\" deleted.") |
| 23 | # OR LIST, to delete file if present. |
| 24 | |
| 25 | # Note logic inversion above. |
| 26 | # AND LIST executes on true, OR LIST on false. |
| 27 | |
| 28 | exit $? |