#!/bin/csh -f # except # ------------------------------------------------------------------------- # Shell script to show all files except those specified. # ------------------------------------------------------------------------- # Revision History: # $Log$ # ------------------------------------------------------------------------- if ($#argv == 0 || $1:q == "-h" || $1:q == "--help") then echo "Usage: $0:t [options] [filename_patterns]" echo " where options are:" echo " -i = Ignore case" echo " -l = Long format (like ls -l), not just names" echo " -v = Verbose. Show the generated pipe of commands" echo " -h = Show this help info" echo " --help = Show this help info" echo "- For best results, invoke via an alias, as:" echo " alias except '(set noglob; \except \!*)'" echo " except *.jpg" echo "- To avoid errors, don't specify filenames that contain spaces," echo " even if you quote or escape them." echo "- If you don't use the alias above:" echo " - For best performance, escape wildcards, as: \*.jpg" echo " - To avoid errors, don't specify wildcards that expand to" echo " filenames that contains spaces, unless you quote or escape" echo " them or use 'set noglob' to prevent expansion, as:" echo " (set noglob; except *.jpg)" exit 1 endif # Collect command line options set name_or_iname_option = "-name" set print_or_ls_option = "-print" set verbose_option = "false" while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then shift # If help option was anywhere among the options, call recursively # with just that option, and exit. This is important because this # script is typically called via an alias that adds more options # before the help option that the user may have specified. $0:t --help exit 1 else if ("$1" == "-i") then shift set name_or_iname_option = -iname else if ("$1" == "-l") then shift set print_or_ls_option = -ls else if ("$1" == "-v") then # Verbose option shift set verbose_option = "true" else # Not a recognized option. Assume it's the first filespec break endif end if ($#argv == 0) then # No -name or -iname option since no filespec was specified # for case to be applied to. set name_or_iname_option = endif # Works perfectly, except when files specified on the command line contain # spaces. How to quote names? set noglob set find_cmd = 'find . -maxdepth 1' foreach filespec ($*:q) set find_cmd = "$find_cmd -not $name_or_iname_option $filespec" end set find_cmd = "$find_cmd $print_or_ls_option" if ($verbose_option == "true") then echo "$find_cmd" endif $find_cmd exit $status