Hi all,
Can somebody answer the following query
Thanks,
Srinivas
A shell program that takes one or any number of file directory names as input; sorts the directories given as parameters jointly in the ascending or decending order of choice For EX : dips abc etc desc will sort the files containied in abc and etc
directories in desending order; in case it is found that one of the given name is directory then an error message should be displayed.
I have tried the following but in vain..
tot_params=$#
echo "The number of parameters supplied = $tot_params"
dir_params=`expr $# - 1`
echo "The number of dir file names supplied = $dir_params"
#index initialization
index=1
# at least two parameters to be supplied
if test $# -lt 2
then
echo "Please enter at least one directory name parameter and one sort parameter"
exit 1
else
# loop thru the all the directories
# listing the file names
# in ascending or descending order
sort_order = $$tot_params
while test $index -le $tot_params
do
file_name = $$index
\# sort parameter is 'ascending'
if test $sort_order = asc
then
echo "File Listing in Ascending Order"
ls -l file_name
\# if the file_name is not a directory
if test $? -ne 0
then
echo "$file_name is not a directory"
exit 1
else
index=\`expr $index\+1\`
fi
\# sort parameter is 'descending'
elif test $sort_order = dsc
then
echo "File Listing in Descending Order"
ls -lr file_name
\# if the file_name is not a directory
if test $ -ne 0
then
echo "$file_name is not a directory"
exit 1
else
index=\`expr $index\+1\`
\# incorrect sort parameter supplied
else
echo "The Sort argument is $$tot_params"
echo "The Directory File name is $$index"
echo "The supplied sort parameter is incorrect"
exit 1
fi
done
fi
if test $? -ne 0
then
echo "sorry..something gone amiss!!!"
else
echo "success"
fi