![]() |
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 |
| Move Command and exit status problem | visingha | Shell Programming and Scripting | 10 | 09-13-2008 08:08 PM |
| Move Command and exit status problem | visingha | UNIX for Dummies Questions & Answers | 1 | 09-12-2008 02:14 AM |
| exit status running java classpath in unix shell | mmcds | High Level Programming | 2 | 08-02-2007 10:06 PM |
| checking exit status of a shell script | kdipankar | Shell Programming and Scripting | 2 | 05-09-2006 01:08 AM |
| Problem with exit status | diganta | Shell Programming and Scripting | 1 | 09-28-2005 08:34 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
sh recursive sub-shell exit status problem
Hi
I am trying to detect the exit status of a recursive function which I am running as a sub-shell. Below I have listed part of the shell script file that I am running...sorry its still a little long winded:- Code:
#!/bin/sh
addFile()
{
fileName="${1##*/}" # Extract filename from path.
if [ $fileName == "phil" ]
then
return 1 #Kick off error...
else
return 0
fi
}
addCommitFiles()
{
# Traverse to database directory or below
cd "$topDir/$1"
if [ $? != 0 ]
then
echo "topDir error $topDir/$1"
exit 1 # Treat as fatal error.
fi
# List all files/dirs in this directory.
ls | while read i
do
# Check if directory.
if [ -d "$i" ]
then
# Pass in full relative path to topDir.
( addCommitFiles "$1/$i" )
ret1=$? # This is never non-zero???
echo "RET=$ret1 != 1"
if [ $ret1 != 0 ]
then
echo "ERR2???"
exit 1 # Treat as fatal error.
fi
echo "ERR3"
else
echo "${rootDir}/$1/${i}"
addFile "$1/$i"
if [ $? != 0 ]
then
echo "ERR1"
exit 1 # We get this error and would exoect
fi
fi
done
exit 0
}
# Main
usrNam="XXX"
topDir=`pwd`
rootDir="./"
(addCommitFiles "./$usrNam")
if [ $? != 0 ]
then
echo "ERROR"
else
echo "OK"
fi
XXX files x y z dir=YYY files x1 y1 z1 dir=ZZZ files phil x2 y2 z2 When I run the shell-script I get the output:- .//./XXX/a .//./XXX/b .//./XXX/c .//./XXX/YYY/x1 .//./XXX/YYY/y1 .//./XXX/YYY/z1 .//./XXX/YYY/ZZZ/phil ERR1 RET=0 != 1 ERR3 RET=0 != 1 ERR3 OK What I dont understand is why I do not get the "ERR2???". I get ERR1 out because addFile returns 1, but I was hoping to get ERR2???" out because the subshell then exits with exit 1. I obviously am missing something here and would be grateful if anyone can help? Thanks Last edited by philp; 01-07-2009 at 05:58 AM.. Reason: Added Code tags |
|
||||
|
Thanks for tour help
1) Sorry I did'nt know about the code tags...I have added them. 2) == works for me? Perhaps my version of bash excepts both??? 3) Brilliant!!! Thankyou " Thre's no need for ls, and it is the cause of your problem, since all elements of a pipeline are run in subshells." This fixed my problem. I dont actually understand why yet, but I will have a read. Thank You!!!! 4) I will remember to use $PWD in the future. In my original code I did not need to know the current directory...this was needed for this cut down version. Thanks Again for all your help!!! |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|