The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Linux Shell Question: how to print the shell script name ? meili100 UNIX for Dummies Questions & Answers 3 07-01-2008 10:55 AM
Difference between writing Unix Shell script and AIX Shell Scripts haroonec AIX 0 04-11-2006 11:27 PM
How to run unix commands in a new shell inside a shell script? hkapil Shell Programming and Scripting 2 01-04-2006 03:56 AM
how to convert from korn shell to normal shell with this code? forevercalz Shell Programming and Scripting 21 11-22-2005 11:18 PM
simple shell - how to get a parameter typed in a shell script cmitulescu Shell Programming and Scripting 3 12-05-2001 12:04 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 10-06-2005
Registered User
 

Join Date: Sep 2005
Posts: 38
how to do in sh shell

Hi,
I am attaching my shell script here then I will put my doubt:

#!/bin/sh
errorexit ()
{
echo Error : $*
echo
}
stval=`cut -d, -f1 ./dir.conf`
for dir in $stval
do
echo " this is $dir"
if [ ! -d "$dir" ]
then
errorexit "$dir" does not exist
fi

if [ ! -x "$dir" ]
then
errorexit "$dir" cannot be accessed
fi

if [ ! -r "$dir" ]
then
errorexit no read permission in $dir
fi

if [ ! -w "$dir" ]
then
errorexit no write permission in $dir
fi
done

the dir.conf is a file which contains the name of directories. I got the directories name and stored it in dir variable. Now I test the different permissions by using if conditions for each directory using for loop.Let say if [ ! -d "$dir" ] is true then it will give some error message. now I face problem like the succesding if statements also executed. Here I cant use exit or break command because it comes out of program. goto command is not understood by sh shell. now my obejective is if any if condtion is true for any directory, it shoul dgive some error message and it should check for another directory which are stored in dir variable. So please help me if any one know. if any more infrmation need then please ask me.
Reply With Quote
Forum Sponsor
  #2  
Old 10-06-2005
Registered User
 

Join Date: Sep 2005
Location: Chennai,India
Posts: 12
Hi,

Try the following script

Code:
 
#!/bin/sh
errorexit ()
{
echo Error : $*
echo
}
stval=`cut -d, -f1 dir.conf`
errorcount=0
for dir in $stval
do
echo " this is $dir"
if [ ! -d "$dir" ]
then
errorexit "$dir" does not exist
continue
fi

if [ ! -x "$dir" ]
then
errorexit "$dir" cannot be accessed
continue
fi

if [ ! -r "$dir" ]
then
errorexit no read permission in $dir
continue
fi

if [ ! -w "$dir" ]
then
errorexit no write permission in $dir
continue
fi
done
Reply With Quote
  #3  
Old 10-06-2005
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,699
Check this out..

Code:
#!/bin/sh
errorexit ()
{
echo Error : $*
echo
}
stval=`cut -d, -f1 ./dir.conf`

for dir in $stval
do
echo " this is $dir"

if [ ! -d "$dir" ]
then
errorexit "$dir" does not exist
elif [ ! -x "$dir" ]
then
errorexit "$dir" cannot be accessed
elif [ ! -r "$dir" ]
then
errorexit no read permission in $dir
elif [ ! -w "$dir" ]
then
errorexit no write permission in $dir
fi
done
vino
Reply With Quote
  #4  
Old 10-06-2005
Registered User
 

Join Date: Sep 2005
Posts: 38
Smile yes it works

thanks monsanbu
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0