ksh - Why is exit_code not correct at end of script? -
asked in google groups, see similar questions asked here ask here also. seem scoping question, variable global far can tell.
tallied exit code zero.
thanks.
ksh -c "exit_code=0; # list of sql files , interate through them work on db. find ./sql_email_reports -maxdepth 1 -type f -print | while read line; echo \"report = \" \${line}; #now sql work on db based on sql file given $line. #and if work db fails reason, send return code greater zero. rc=\$?; # test incrementation of exit_code setting rc, should increment exit_code every file found in directory. rc=1 echo \"rc = \" \${rc}; (( exit_code+=rc )); echo \"exit code =\" \${exit_code}; done; enter code here # reason, tallied exit_code not within while loop, still 0 echo \"tallied exit_code = \" \${exit_code}; (( exit_code > 0 )) && exit 1; exit 0;"
the while loop runs in subshell, variable manipulations not visible parent.
this faq. http://mywiki.wooledge.org/bashfaq/024 aimed @ bash users, applies ksh , posix shell well.
Comments
Post a Comment