Date: Mon, 20 Jul 2020 10:11:59 -0400 From: Chet Ramey <chet.ra...@case.edu> Message-ID: <a62804af-8c7f-5191-362b-ef5f4d7b3...@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