On 10/4/17 6:10 PM, Martijn Dekker wrote: > 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). > > Hmm... > > v=~/bla > printf '%s\n' "$v" > > outputs /Users/martijn/bla on all shells, so tilde expansion applies for > a simple assignment anyway. > > And > > unset -v v > v=${v:=~/bla} > printf '%s\n' "$v" > > acts exactly the same. > > This is all POSIXly correct, IIRC.
That's not quite what I meant. The difference between an assignment context and a non-assignment word is that Posix specifies that tilde expansion is performed following `:'. "In an assignment (see XBD Variable Assignment), multiple tilde-prefixes can be used: at the beginning of the word (that is, following the <equals-sign> of the assignment), following any unquoted <colon>, or both." Given the following script: HOME=/usr/xyz XPATH=/bin:/usr/bin:. ADDPATH=${ADDPATH:-~/bin:~/bin2:$XPATH} echo "$ADDPATH" unset ADDPATH : ${ADDPATH:=~/bin:~/bin2:$XPATH} echo "$ADDPATH" unset ADDPATH Different shells will treat the `:~' tilde prefix differently between the two statements, since they don't consider the := expansion a variable assignment. It would be nice if the shell were consistent in this regard. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/