Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have this for loop...It reads a bunch of configuration files and for each file it should call the function function_process. After function_process had been executed is should read the next configuration file and call the function again and do this for all the configuration files.However, after the first execution of the function_process for the first configuration file it exits.
#Main functionfor file in `find . -name "*.cnf" -exec grep -l tocode {} \; ` ;
do
tocode=`awk -F= '/tocode/ { print $2 }' $file | sed -e "s/'//g"`
stream=`awk -F= '/stream/ { print $2 }' $file | sed -e "s/'//g"`
if [[ ! -n "$stream" ]]; then
FMASK=`awk -F= '/FMASK/ { print $2 }' $file | sed -e "s/['\^]//g"`
stream=$FMASK
fi
if [[ ! -d $TESTDIR/$stream ]]; then
mkdir "$TESTDIR/$stream"
function_process $stream $tocode
fi
donefunction_process
{stream=$1
tocode=$2function definition
}
Does anyone have an idea about how to solve this or does anyone sees what's going wrong in my
main function?Thanks for you help in advance

Define your function before you plan to use it. Enable debugging with "set -x" to help you see what is happening. Where is $testdir defined ?
function_process () {
stream=$1
tocode=$2
function definition
}for file in `find . -name "*.cnf" -exec grep -l tocode {} \; ` ; do
tocode=`awk -F= '/tocode/ { print $2 }' $file | sed -e "s/'//g"`
stream=`awk -F= '/stream/ { print $2 }' $file | sed -e "s/'//g"`
if [ -z "$stream" ]; then
FMASK=`awk -F= '/FMASK/ { print $2 }' $file | sed -e "s/['\^]//g"`
stream=$FMASK
fiif [ ! -d ${TESTDIR}/${stream} ]; then
mkdir ${TESTDIR}/${stream}
function_process $stream $tocode
fi
done

Hi David,
Thank you for your reply.
TESTDIR is defined in an include file. When I manually delete the processed configuration file...and execute the shell scripts again...then it processes it properly. so..it just doesn't return to the for loop to get the next config file.

Include
set -xat the top of your script as well as within the function. Also, if you are using ksh, you can include this after the set -x line
PS4='$0 line $LINENO: '
This should tell you where the break is happening.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |