#!/bin/csh -f # catdel # ----------------------------------------------------------------------------- # Shell script to show and offer to delete specified files # ----------------------------------------------------------------------------- # Usage: See Usage section below or run with -h or --help to see usage. # Assumptions: # Effects: # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ----------------------------------------------------------------------------- while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options] file..." echo "Options:" echo " -h = Show this help text" echo " --help = Show this help text" exit 1 else if ("-" == "`echo $1:q | cut -c 1`") then beep "Error: Invalid option: $1:q" $0 --help exit 1 else # Not a recognized option. Assume it's the first argument break endif end # Collect command line arguments if ($#argv < 1) then beep "Error: No filename specified." $0:t --help exit 1 endif set rc = 0 foreach file ($*:q) if (-l "$file") then # Check this before -e because -e returns false for existing symlink # to non-existing file. echo "$file is a symlink" ls -Fl "$file" else if (! -e "$file") then beep "Error: $file does not exist" exit 1 else if (! -r "$file") then beep "Error: $file cannot be read" exit 1 else if (-z "$file") then echo "$file is empty" else if (-d "$file") then echo "Skipping subdirectory $file ..." continue else if ($#argv > 1) then # Make it easier to spot next file when doing multiple files echo "" echo "" echo "" echo "" endif echo "Showing $file..." # -S = Wrap long lines less -S "$file" endif rm -iv "$file" set rc = $status if ($rc != 0) then exit $rc endif end exit $rc