The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-06-2001
psrinivas psrinivas is offline
Registered User
  
 

Join Date: Oct 2001
Location: London
Posts: 2
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
  #2 (permalink)  
Old 12-06-2001
LivinFree's Avatar
LivinFree LivinFree is offline Forum Advisor  
Goober Extraordinaire
  
 

Join Date: Jul 2001
Location: Portland, OR, USA
Posts: 1,584
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...
  #3 (permalink)  
Old 12-06-2001
psrinivas psrinivas is offline
Registered User
  
 

Join Date: Oct 2001
Location: London
Posts: 2
Unhappy new bourne shell script

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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0