Date: Tue, 12 May 1998 08:20:01 -0700 (PDT) From: Martin Cracauer <cracauer@cons.org> To: freebsd-bugs@FreeBSD.ORG Subject: Re: bin/6557: /bin/sh && IFS Message-ID: <199805121520.IAA25528@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/6557; it has been noted by GNATS. From: Martin Cracauer <cracauer@cons.org> To: dima@best.net, FreeBSD-gnats-submit@FreeBSD.ORG Cc: Subject: Re: bin/6557: /bin/sh && IFS Date: Tue, 12 May 1998 17:22:13 +0200 In <199805082158.OAA01692@burka.rdy.com>, dima@best.net wrote: > /bin/sh doesn't work as it supposed to when dealing with $IFS > variable. > > >How-To-Repeat: > > Try to run this script: > > #!/bin/sh > XXX=/1:/2:/3: > IFS=: > echo /0:$XXX > > The expected result should be: "/0 /1 /2 /3" > However, with current /bin/sh it's: "/0:/1 /2 /3" This has been discussed before, see http://www.freebsd.org/cgi/query-pr.cgi?pr=5263. My reply to this PR has a fix in it, which fixes both your case and the GNU autoconf case. However, it is my current opinion that my fix and bash are wrong. Hence I didn't commit it although you are invited to see if it fits your needs, it's in the url given above. I still don't have a POSIX reference, but I've been told that POSIX specifies that word splitting is to be done during evaluation, not during parsing. I think it's obvious that IFS split is part of word splitting. The question at hand is: How does IFS splitting fit into the picture? The value of $IFS is obviously a result of evaluation, but a result that affects parsing, at least this is what bash tries to do. This sounds very counter-intuitive, how can you define clean sematics for changing the lexical structure while parsing? Consider this: #! /bin/sh IFS=" :" var="bla:fasel:blubb" echo foo:bla:fasel:blubb echo foo:$var bash: foo:bla:fasel:blubb foo bla fasel blubb FreeBSD's unpatched sh and pdksh: foo:bla:fasel:blubb foo:bla fasel blubb My patched FreeBSD sh: foo bla fasel blubb foo bla fasel blubb zsh (doesn't really count): foo:bla:fasel:blubb foo:bla:fasel:blubb What bash and my fix do is that they treat IFS as something that is used "as soon as possible" (while in my fix it is possible even sooner as in bash). My current conclusion is that this is wrong, that IFS *must* *not* affect the basic (top-level script file) paring, but that IFS splitting can happen when the parsed script again begins to parse something. Examples for such later parsing: - The contents of a string are parsed as in var="bla:fasel:blubb" - Some run-time input to the script. To make my point clearer: If bash is right in using IFS during the same parse pass, why doesn't it take it as far as my patch? How can you decide which of both is correct? For now, the only clean solution is not to use IFS for the top-level parse, hence I think FreeBSD's sh (ash) and pdksh are right and autoconf needs to be fixed (given that the fix is always a one-liner that can't be so difficult). Suggestions and comments welcome! Martin -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer BSD User Group Hamburg, Germany http://www.bsdhh.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199805121520.IAA25528>