bourne shell script

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

Well, without actually doing your homework for you, I can say you definitely use "test" better...
(Hint: test -f, test -d... man test)

Also, what errors are you getting?

Have you tried placing "set -x" near the top of the script? Try that to see where it's failing...

Hi mate,
I have modified my script , after your suggestion.

I guess the specific issue for me is the 'parameterization' of the shell script arguments thru a local variable 'index' .is there an alternative to this.

          for example : how do i get the argument value of the 'n'th argument to the shell script . 

           can you address this problem .

Thanks
srinivas

set -x

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

    while test $index -le $tot_params 
    do
            file_name = $\($index\)
            
            \# sort parameter is 'ascending'

            if test $\# = asc
            then
                    if test -d $file_name
                    then
                            echo "listing the files in ascending order....."
                            ls -l $file_name
                            index=\`expr $index\+1\`
                    else
                            echo "$file_name is not a directory"
                            exit 1
                    fi
    
            \# sort parameter is 'descending'

            elif test $\# = dsc
            then
                    echo "File Listing in Descending Order"
                    if test -d $file_name
                    then
                            echo "listing the files in descending order..."
                            ls -lr $file_name
                            index=\`expr $index\+1\`
                    else
                            echo "$file_name is not a directory"
                            exit 1
                    fi
            
            \# incorrect sort parameter supplied     

            else
                    echo "The Sort argument is $\($\#\)"
                    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