On 11/29/2011 02:00 AM, Gary wrote: > If I have a shell script which reads a file which does not have an end > of line character at the end if it's only line, it does not read > anything.
Not cygwin specific. > > For example: > ,---- > | #!/bin/sh > | > | fileName="test.xml" Your example didn't tell us the contents of test.xml. But this is reproducible even without knowing the contents of test.xml. > | retVal="Z" > | > | exec 10<&0 > | exec < $fileName > | while read configLine read(1) is required to return non-zero status when it encounters a partial line (one with no end of line character). Which means that since testXML had no newline character, read never returned status 0, which means you never entered the body of the while loop, > | do > | retVal="A" which means retVal was never assigned. > | done > | exec 0<&10 10<&- > | > | echo $retVal So this is echoing an unassigned variable, as required by POSIX. > | > | exit 0 > `---- > > If it's expected behaviour, what's the workaround? Never feed 'read' unterminated input. Always end your text files with a newline. -- Eric Blake ebl...@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature