Bash supplies the codes needed to determine file type. A for-next loop to cycle through filenames and an if-then-elif-fi agrument to make decisions based on file type and permissions would complete the process.
Here is a script I wrote for my Linux class a couple of years ago. It includes some of the code you would need. The script is documented so that you can understand what is supposed to happen (it works, btw).
All you need to do is study the code in this script, and adapt the processes to your needs.
Don't forget 'man bash' and 'info bash'. Also, the 'Advanced Bash Scripting Guide'.
Code:
#!/bin/bash
# lvidrineproj2.sh
# The program takes two command line arguments. If more or # less than two args are given, the user gets an appropriate # error message. Then, give the user information about the #arguments: are they file names; are they
# regular files or directories; who owns the files; which file is #newer.
echo; echo
if [ $# -ne 2 ]; then
echo "Please supply two filenames, no more and no less." echo "Usage: $0 <filename_1> <filename_2>" 1>&2
echo "Exiting"
exit 10
fi
# have user verify that file names are entered correctly
echo; echo "You entered '$1' and '$2' for testing."
echo; echo "Please confirm that you entered the arguments correctly,"
echo "no typographical errors. Enter y for yes; n for no."
read confirm
while [ "$confirm" != "y" -a "$confirm" != "n" ] do
echo "Enter y or n only."
echo "Re-enter your answer: y or n."
read confirm
done
if [ "$confirm" = "n" ]; then
echo "You say you made a typo."
echo "Exiting this script."
echo
exit 20
fi
# check for valid filename entries in this directory
if [ -e "$1" -a -e "$2" -a -r "$1" -a -d "$2" ]; then
echo "$1 is a regular file; $2 is a directory."
echo "Exiting"
exit 40
elif [ -e "$1" -a -e "$2" -a -d "$1" -a -r "$2" ]; then
echo "$1 is a directory; $2 is a regular file."
echo "Exiting"
exit 40
elif [ -e "$1" -a -e "$2" -a ! -d "$1" -a ! -r "$1" -a \ ! -d "$2" -a ! -r "$2" ]; then
echo "Neither file is a directory or regular file."
echo "Exiting"
exit 30
elif [ ! -e "$1" -a ! -e "$2" ]; then
echo "Neither file exists in this directory."
echo "Exiting"
exit 30
elif [ ! -e "$1" -o ! -e "$2" ]; then
echo "One of the files doesn't exist in this directory."
echo "Exiting"
exit 30
else [ -e "$1" -a -e "$2" -a -r "$1" -a -r "$2" ]
echo "Both files exist in this directory."
echo "Both files are regular files."
fi
if [ "$confirm" = "y" ]; then
# does user own the files being tested?
if test -O "$1"; then
echo "$1 is owned by $USER"
else
echo "$1 is not owned by $USER"
fi
if test -O "$2"; then
echo "$2 is owned by $USER"
else
echo "$2 is not owned by $USER"
fi
fi
echo
# which file is newer?
if test $1 -nt $2 ; then
echo "'$1' is newer than '$2'"
elif test $2 -nt $1 ; then
echo "'$2' is newer that '$1'"
else
echo "'$1' and '$2' were created at the same time."
fi
echo
echo