I am trying to read a file line by line using while loop like:
while read Line; do
echo Inside outer loop
while read Line2; do
.....
echo Inside inner loop
.....
done < /absolute path of file/filename2
done < /absolute path of file/filename
The script is working fine when running standalone. But it does not go inside loop when it gets run from crontab.
Please suggest what could be the possible reason of it.
The 2nd while loop is reading all the input (except for the first line of "filename"). You need to redirect to separate file descriptors:
while IFS= read -r -u3 Line; do
echo Inside outer loop
while IFS= read -r -u4 Line2; do
.....
echo Inside inner loop
.....
done 4< "/absolute path of file/filename2"
done 3< "/absolute path of file/filename"
IFS= and read -r to ensure the line is read verbatim from the file. read -u3 and 3< file to use a specific fdIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With