1
I'm having a problem that is extremely odd to me.
I have a loop that reads a file line by line that looks something like this:
while read line; do
echo "Beginning of loop"
## Call to function that executes .bat file
echo "End of loop"
done < $MANIFEST
echo Outside of Loop
I call the .bat file in a sub shell, so it shouldn't affect any of my variables. It looks something like this:
$(CMD /c c.bat -c "$SCR_DIR/prepsdk.sh Build $apppath")
The weird thing is that the bat file terminates my loops somehow. Meaning I will see the following output:
Beginning of Loop Output from .bat End of Loop Outside of Loop
If the call to .bat is commented out I see
Beginning of Loop End of Loop Beginning of Loop End of Loop ..... Beginning of Loop End of Loop Outside of Loop
So the behavior is as expected with the .bat file not being called. What is it that the .bat file could be doing that causes the loop to terminate like this? It's not modifying the $MANIFEST file, I made sure of that.
In which case, the solution would be to read
$MANIFEST
on a different file descriptor than standard input:while read -u3 line; do ...; done 3< $MANIFEST
– chepner – 2012-08-10T19:37:34.813I don't understand how this bat file could possibly be modifying the manifest file, but using a different file descriptor solved the problem. – Millianz – 2012-08-10T20:27:29.660
The batch file wasn't modifying the file, it was reading from standard input -- everything from standard input, leaving nothing for the next invocation of
read
to get, soread
exited with a non-zero status, terminating the loop. That was my theory. – Fran – 2012-08-11T15:58:08.160Ah I see that makes a lot more sense. Thank you :) – Millianz – 2012-08-16T00:12:22.920