Nested While loop doesn't end

Hi,

Below is my script in which i am using nested while loop to read two files and move the files to a remote server.

My issue is that the 2nd while loop doesn't stop executing and it keeps on executing.

Can someone please let me know where i have gone wrong.

myFile=$ESER_TEST_FILES

date=`date +"%Y%m%d%H%M%S"`

while read line
do
    dir=`dirname "$line"`
    I_CLI_CODE="`print $line | cut -f4 -d'/'`"
    base=`basename "$line"`
    echo $base
    $JAVA_COMMAND -classpath ${PROCESSES_HOME_DIR}:/nfs/automationworks/lib/ojdbc14.jar:. ${PATH_PACKAGE}.TestFileHandle $I_CLI_CODE
    cli_code=$I_CLI_CODE

    myFile=$GETCLIENT_NAME_STATUS
    while read line
    echo $line
    do 

        cli_name="`print $line | cut -f2 -d'/'`"
        cli_status="`print $line | cut -f3 -d'/'`"

        if [ -d $SCPED_TEST_FILES"$cli_name"_$cli_code ]
        then
            echo "$DIR directory  exists!"
        else
            mkdir $SCPED_TEST_FILES"$cli_name"_$cli_code
        fi

        
            filename=$base-$date
            echo $filename
            #Appending the filename with date and time

            mv "$ETEST_FILE_LOC$cli_code/$base" $SCPED_TEST_FILES"$cli_name"_$cli_code/$filename

            echo $cli_name

            sudo -u vty scp -r $SCPED_TEST_FILES"$cli_name"_$cli_code vty@fs1.local:'/cygdrive/d/TEST\ files/$cli_name$cli_code'

            print "$ETEST_FILE_LOC$cli_code/$filename $SCPED_TEST_FILES"$cli_name"$cli_code"                                    >> $TEST_FILE_LIST
            echo false;;
        esac

    done < $GETCLIENT_NAME_STATUS

done < $ESER_TEST_FILES

Thanks

  while read line
    echo $line
    do 

should be

 while read line2
    do 
      echo $line2

also make sure that the variables storing the filenames that you loop through are set.
That is, those GETCLIENT_NAME_STATUS a ESER_TEST_FILES.

But your biggest issue is that you use the same variables in both loops: line.
You should use something else, like "line2" in the second, nested loop.

1 Like

thanks a lot... got it working...