[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Assignment-like word shouldn't be subjected to tilde expansion in PO
From: |
Robert Elz |
Subject: |
Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode |
Date: |
Thu, 30 Jul 2020 21:43:40 +0700 |
Date: Mon, 20 Jul 2020 10:11:59 -0400
From: Chet Ramey <chet.ramey@case.edu>
Message-ID: <a62804af-8c7f-5191-362b-ef5f4d7b3db8@case.edu>
Sorry, didn't reply to this at the time...
| You can make a case for the bash/ksh tilde expansion: the word
| expansion is ${PARAM:=WORD}, and the WORD is subject to tilde expansion
| according to the enumerated list in 2.6.2.
Sure. but ...
| Since the first character of WORD is a tilde, if you say the
| tilde-prefix stops at the `:',
but that's true (in posix) only in an assignment. Either it is an
assignment, or it is not. If it isn't, then in
echo ${foo=~:~otheruser}
the "tilde-prefix" would be ~:~otheruser and since it is kind of unlikely
that there's a user named ":~otheruser" the lookup should fail (leading to
undefined results). Most non ksh/bash shells simply leave the entire
word unaltered (which is probably what should be specified to happen if
the username lookup fails, that is in line with other expansion failures
that fail depending upon external data (like *.c when there are no .c
files) rather than those which fail because of broken syntax ("${foo]")
If it is an assignment, then the ':' does end the tilde-prefix, and
we expand the bare '~' but in that case, a ~ immediately after the
':' starts another tilde-prefix ("~otheruser" in this case) which
should result in a lookup of "otheruser" (which might succeed, and can
be made to by sane selection of a replacement for that name).
Since ${X=anything} is clearly (really) an assignment when X was
previously unset, this is how I treat it, and...
Assign Default Values. If parameter is unset or null, the
expansion of word (or an empty string if word is omitted)
shall be assigned to parameter.
Looks and smells like an assignment to me. Further, XCU 2.6.1
says "In an assignment" not "In a variable assignment" even though
it references XBD 4.23 (which is the definition of "variable assignment")
so I think it entirely reasonable to treat the assignment in the
"assign default values" parameter expansion as an assignment for the
purposes of tilde expansion, and the xref just being one of the
kinds of assignment that this might apply to.
kre
Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode, M. Nejat AYDIN, 2020/07/21
- Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode, Greg Wooledge, 2020/07/21
- Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode, M. Nejat AYDIN, 2020/07/21
- Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode, Greg Wooledge, 2020/07/21
- Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode, M. Nejat AYDIN, 2020/07/21
- Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode, M. Nejat AYDIN, 2020/07/21