|I am not a cygwin user, but a unix-type shell should not act this way. I suggest you try placing the commands that create and update files with '>' and '>>' within parenthesis. This forces the spawn of a new shell.|
Here is an example:
echo "hello world" > myfile.txt
echo $x # reverts back to 5
When the new shell is spawned, the myfile.txt file should be created, I change the value of x to 7. This demonstrates that a new shell was created when x reverts back to 5.