Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Robert Elz Newsgroups: gnu.bash.bug Subject: Re: Assignment-like word shouldn't be subjected to tilde expansion in POSIX mode Date: Thu, 30 Jul 2020 21:43:40 +0700 Lines: 50 Approved: bug-bash@gnu.org Message-ID: References: <5f066ef0-1fed-ad5b-d564-490268d32427@case.edu> <8ddc4816-f85e-97b3-5c51-9b55acdcaca5@case.edu> <26757.1595233713@jinx.noi.kre.to> <7963.1596120220@jinx.noi.kre.to> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1596120269 10990 209.51.188.17 (30 Jul 2020 14:44:29 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: chet.ramey@case.edu Envelope-to: bug-bash@gnu.org In-Reply-To: Received-SPF: permerror client-ip=2001:3c8:9009:181::2; envelope-from=kre@munnari.OZ.AU; helo=munnari.OZ.AU X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -8 X-Spam_score: -0.9 X-Spam_bar: / X-Spam_report: (-0.9 / 5.0 requ) BAYES_00=-1.9, KHOP_HELO_FCRDNS=1, T_SPF_HELO_PERMERROR=0.01, T_SPF_PERMERROR=0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <7963.1596120220@jinx.noi.kre.to> X-Mailman-Original-References: <5f066ef0-1fed-ad5b-d564-490268d32427@case.edu> <8ddc4816-f85e-97b3-5c51-9b55acdcaca5@case.edu> <26757.1595233713@jinx.noi.kre.to> Xref: csiph.com gnu.bash.bug:16648 Date: Mon, 20 Jul 2020 10:11:59 -0400 From: Chet Ramey Message-ID: 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