[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Spaces trimmed from $* when assigned while IFS is unset [was: Unexpe

From: Martijn Dekker
Subject: Re: Spaces trimmed from $* when assigned while IFS is unset [was: Unexpected word splitting on $* ...]
Date: Thu, 5 Oct 2017 00:10:06 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

Op 04-10-17 om 17:52 schreef Chet Ramey:
> It's interesting that other shells treat ${a:=b} as kind of like an
> assignment statement (word splitting) but not quite (tilde expansion).


        printf '%s\n' "$v"

outputs /Users/martijn/bla on all shells, so tilde expansion applies for
a simple assignment anyway.


        unset -v v
        printf '%s\n' "$v"

acts exactly the same.

This is all POSIXly correct, IIRC.

Of course, when ${v:=~/bla} is an unquoted expansion in a non-assignment
context, field splitting and pathname expansion apply to the expansion,
but not to the assignment itself, which is also perfectly logical:

        [ -n "${ZSH_VERSION+s}" ] && emulate sh
        unset -v v
        touch /tmp/foo.bar /tmp/baz.bar
        printf 'field: [%s]\n' ${v:=~/one ~/two /tmp/*.bar}
        printf '  var: [%s]\n' "$v"

Output on bash, dash, FreeBSD sh, Busybox ash, yash, pdksh, mksh, ksh93,
zsh up to 5.0.8:

        field: [/Users/martijn/one]
        field: [~/two]
        field: [/tmp/baz.bar]
        field: [/tmp/foo.bar]
          var: [/Users/martijn/one ~/two /tmp/*.bar]

Output on zsh 5.1 and later, it seems to do tilde expansion after word
splitting instead of before -- which looks like a bug[*2], I'll take
that up there:

        field: [/Users/martijn/one]
        field: [/Users/martijn/two]
        field: [/tmp/baz.bar]
        field: [/tmp/foo.bar]
          var: [/Users/martijn/one ~/two /tmp/*.bar]

Output on bosh (schilytools) and NetBSD sh -- clearly a bug, it doesn't
do tilde expansion at all:

        field: [~/one]
        field: [~/two]
        field: [/tmp/baz.bar]
        field: [/tmp/foo.bar]
          var: [~/one ~/two /tmp/*.bar]

- Martijn


reply via email to

[Prev in Thread] Current Thread [Next in Thread]