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 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 09:08 PM
Move Command and exit status problem visingha UNIX for Dummies Questions & Answers 1 09-12-2008 03:14 AM
exit status running java classpath in unix shell mmcds High Level Programming 2 08-02-2007 11:06 PM
checking exit status of a shell script kdipankar Shell Programming and Scripting 2 05-09-2006 02:08 AM
Problem with exit status diganta Shell Programming and Scripting 1 09-28-2005 09:34 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 01-06-2009
philp philp is offline
Registered User
  
 

Join Date: Jan 2009
Posts: 2
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

I have created the following directory structure in my local directory:-
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
 

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 02:16 PM.


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