(no match) script takes filenames (usually, expanded by the shell) from
its command line.
It outputs all filenames in the current directory that
that works like
but other shells don't.
Here are some examples of
To get the names of all files that
To edit all files whose names don't have any lowercase letters, use
command substitution (
vi `nom *[a-z]*`
To copy all files to a directory named
cp `nom Backup` Backup
Here's the script:
stat=1 # ERROR EXIT STATUS (SET TO 0 BEFORE NORMAL EXIT)
trap 'rm -f $temp; exit $stat' 0 1 2 15
# MUST HAVE AT LEAST ONE ARGUMENT. ALL MUST BE IN CURRENT DIRECTORY:
case "$*" in
"") echo Usage: `basename $0` pattern 1>&2; exit ;;
*/*) echo "`basename $0` quitting: I can't handle '/'s." 1>&2; exit ;;
# GET NAMES WE DON'T WANT TO MATCH; REPLACE BLANKS WITH NEWLINES:
echo "$*" | tr ' ' '\012' | sort > $temp
# COMPARE TO CURRENT DIRECTORY (-1 = ONE NAME PER LINE); OUTPUT NAMES WE WANT:
ls -1 | comm -23 - $temp
You can remove the
option on the script's
line if your version of
lists one filename per line by default;
almost all versions of
do that when they're writing into a pipe.
doesn't know about files whose names begin with a
); you can change that if you'd like by adding
option (uppercase letter "A", which isn't on all
The script line with
will split filenames containing space characters.
You can replace that line with
the following three lines;
they run more
slowly on some shells but will fix this (unlikely) problem:
do echo "$file"
done | sort > $temp