![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Bourne Shell script - log for users loggin on and off | noodlesoup | Shell Programming and Scripting | 14 | 09-08-2006 10:30 PM |
| Bourne: How to invoke an alias from within a shell script | techshots | Shell Programming and Scripting | 2 | 06-04-2006 12:38 AM |
| cd from a Bourne Shell Script - Please Help | fawqati | Shell Programming and Scripting | 10 | 05-25-2006 03:26 AM |
| Bourne Shell Script | dmhonor914 | UNIX for Dummies Questions & Answers | 2 | 12-10-2003 12:25 PM |
| Bourne shell script need help please ? | dezithug | UNIX for Advanced & Expert Users | 7 | 10-24-2001 01:59 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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 Last edited by psrinivas; 12-11-2001 at 08:53 AM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|