----- Original Message ----- From: "Patrick Shanahan" <paka@opensuse.org> To: <opensuse@opensuse.org> Sent: Thursday, September 04, 2008 7:47 AM Subject: Re: [opensuse] BASH - howto 'read' line in file and preserve leading whitespace?
* Brian K. White <brian@aljex.com> [09-04-08 06:35]:
Becomes this:
DONE=false until $DONE ;do IFS="" read || DONE=true [...] done <infile >outfile
Shouldn't you clean-up after yourself and reset the $IFS to it's expected value?
Nope. There is nothing to clean up. IFS has not been changed. When a variable is set in this manner, on the same line as, and preceding, a command, it only affects the environment of the command, not the current environment. Try this: FOO=yes FOO=no eval 'echo $FOO' echo $FOO FOO=yes affects the current environment FOO=no affects only the environment of "eval..." You need this eval syntax as a way to enclose $FOO in single-quotes to keep the current shell from expanding $FOO itself before handing it to echo. If you say for instance: FOO=yes FOO=no echo $FOO It will say "yes" , which may confuse the heck out of you. What happens in that case is, the current environment has FOO=yes Then we set FOO=no in echo's environment, but we never see that because "echo $VARIABLE" does not resolve VARIABLE out of echo's own environment. echo just echos things from it's command line. echo's command line was assembled by our current shell, which expanded $FOO from IT'S environment before invoking echo. A clearer example may be: FOO=yes FOO=no awk 'BEGIN{print ENVIRON["FOO"]}' </dev/null echo $FOO That way we never used the syntax $FOO, so there is no possible confusion about which instance of which shell might have expanded it. It had to come from awk's environment. -- Brian K. White brian@aljex.com http://www.myspace.com/KEYofR +++++[>+++[>+++++>+++++++<<-]<-]>>+.>.+++++.+++++++.-.[>+<---]>++. filePro BBx Linux SCO FreeBSD #callahans Satriani Filk! -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org