Date: Mon, 07 Apr 2008 05:21:55 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Julian Elischer <julian@elischer.org> Cc: freebsd-hackers@freebsd.org, dino <dino@unitix.org> Subject: Re: bug in /bin/sh?!? Message-ID: <87ve2ujtfg.fsf@kobe.laptop> In-Reply-To: <47F913AE.3040604@elischer.org> (Julian Elischer's message of "Sun, 06 Apr 2008 11:17:18 -0700") References: <47F8C1B3.4030902@unitix.org> <47F913AE.3040604@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 06 Apr 2008 11:17:18 -0700, Julian Elischer <julian@elischer.org> wrote: > dino wrote: >> Hello, >> >> on my FreeBSD 7.0-STABLE the line: >> >>> sh -c 'set -- ${HOME+A B C}; echo "1:$1"; echo "2:$2:"; echo "3:$3:"' >> >> prints >> >> 1:A B C: >> 2:: >> 3:: >> >> I would rather expect: >> >> 1:A: >> 2:B: >> 3:C: >> >> Is it correct that field splitting isn't performed on default/alternate >> expanded values? > > "A B C" is a single value tha thappens to contain spaces. > so, yes there is no splitting at that point. I think there *is* splitting. To inhibit splitting, you would have to use quotes, i.e. one of: set -- "${HOME+A B C}"; echo "1:$1"; echo "2:$2"; echo "3:$3" set -- ${HOME+"A B C"}; echo "1:$1"; echo "2:$2"; echo "3:$3" Splitting does occur in bash, mksh, pdksh and zsh in FreeBSD. The Solaris 10 version of /bin/sh shell does not accept the original at all (I used Solaris 10 Update 3, aka "Solaris 10 11/06 s10x_u3wos_10 X86", for the test): $ sh -c 'set -- ${HOME+A B C}; echo "1:$1"; echo "2:$2:"; echo "3:$3:"' sh: bad substitution $ but it does accept any of the quoted options. The /usr/bin/ksh shell on Solaris accepts the original, but it splits the result at whitespace.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?87ve2ujtfg.fsf>