[Gllug] newbie- shell script
Tethys
tet at accucard.com
Fri Dec 27 15:44:51 UTC 2002
"Manjush G. Menon" writes:
>I want to write a shell program that takes one or any number of
>file directory names as input; sorts the directory listings of all the
>directories given as parameters jointly in the ascending or
>descending order of choice.
Here you go:
#!/bin/sh
prog=`basename "$0"`
tmpfile="/var/tmp/$prog.$$"
trap "/bin/rm -f \"$tmpfile\"" 0 INT HUP QUIT TERM
if [ $1 = "-r" ]
then
sortargs=-r
shift
fi
cp /dev/null "$tmpfile"
for dir in "$@"
do
if [ ! -d "$dir" ]
then
echo "$prog: $dir is not a directory" 1>&2
continue
fi
(
cd "$dir"
ls -1 >> "$tmpfile"
)
done
sort $sortargs "$tmpfile"
Give it a list of arguments, optionally preceded by a "-r" flag to
reverse the sort order.
Tet
--
Gllug mailing list - Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug
More information about the GLLUG
mailing list