![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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
|
|
#3
|
||||
|
||||
|
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
|
|
#4
|
|||
|
|||
|
thanks
|
|||
| Google The UNIX and Linux Forums |