shell script behavior is strange or I'm not understanding

Hi
I have wrote the small script, where $SRC=$HOME
the input file is simple text file having directories in my $SRC on pre line

desktop
download
myfiles
games
#!/bin/bash
FILENAME=$1
ERROR_LOG="$SRC/err.$$.log"
while read line
do
   echo "########## strat Gmake $line #######" >$ERROR_LOG
   echo $line >>$ERROR_LOG
   cd $SRC
   cd  $line
   echo `pwd` >>$ERROR_LOG
   #gmake
   cd $SRC
   echo "############ End of Gmake $line #######">>err.$$.log
done < $FILENAME

I am expecting this to print [strat Gmake $line] .... [End of Gmake $line] section for every directory, available in the input file.

Kindly help to if my expectation is wrong from this code ... as I m not getting desired result. it is just printing the section [strat Gmake $line] .. [End of Gmake $line] for last directory in the input file.

Someone help me out to understand where is the catch

On line 6 pls try this

echo "########## strat Gmake $line #######" >>$ERROR_LOG
1 Like

1) Where is SRC initialized in your script ? you should set it up
2) since you use a loop, if you use a simple redirection >$ERROR_LOG this will erase previous entries in your log file

1 Like
echo "########## strat Gmake $line #######" >$ERROR_LOG

This is overwritting the file for every loop run.
Pls use

echo "########## strat Gmake $line #######" >> $ERROR_LOG
1 Like

Where did you set $SRC (exported in .profile?)

HTH,
tyler_durden

Thanks to all I didnt realize that >$ERROR_LOG

That was completely out of my review process.
Thanks once again to draw my attention to that stupid mistake.
:slight_smile: