Path: csiph.com!weretis.net!feeder6.news.weretis.net!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: Stephane Chazelas Newsgroups: gnu.bash.bug Subject: Re: Locale not Obeyed by Parameter Expansion with Pattern Substitution Date: Mon, 18 Nov 2019 20:46:26 +0000 Lines: 52 Approved: bug-bash@gnu.org Message-ID: References: <0acc4767-e87f-f163-b39e-f137effdfea2.ref@sbcglobal.net> <0acc4767-e87f-f163-b39e-f137effdfea2@sbcglobal.net> <20191118204626.33smprow5zae4apl@chaz.gmail.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: usenet.stanford.edu 1574109997 27526 209.51.188.17 (18 Nov 2019 20:46:37 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: Chris Carlen Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=X+RJ84syPyU8Niy84PazizpUFbAWwnJTz9SwjzY/xvg=; b=mXxMzORUu/zq3YMfdS/KPptwdUTh6daz7n1ECDxiafdQV/lXT43cpxUJSf4JZBc6Zr V4XwzkQIeq9vFO3DCTURMt6WMIKPRSRC1K2MhHNCaTwpAtv2boFZUtbDXtSAalEVH2g8 iUmCwzJ+Es9E0ovqdItd1ZWlghkbOvE8xXIKXwu/ZId1QhdBa2s0YbOqwMAQ3tG+4DDI QFxWCtO3x9uVQs/F97rtHHcovGYgK/rF3dhl8d9DeUeT0DF2hahYCoBcSxRzjr7Vz/cF k1538K5lGJorV5cA6b/pgT10bbSN6uYTsbsbDNYp3nTkCTyg7Xsqxbrb6CSwp7r+i+hn ICNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=X+RJ84syPyU8Niy84PazizpUFbAWwnJTz9SwjzY/xvg=; b=hEd5MD3eyL8yooZczTKk6IbPwErD8bPSiPmGuIwWSpTPWTeJOFbBYfc2rt2NvtH/Wq 2XsW8UXAvmlD6946RV/Xht+QI4pcm7Pv5q7MyAOEdnKYUufmS3B2u/1lpwcthkQB2lxA 608yf6DreY9NVZjTUM/At/yj9XHiy5TQsqKwHvPCFzJLqr6slvx+JPsOWVUX8VCQQInq 9XLyL8cQpEikn3S5s+NIaJdAsqd42nNTEsztSFAzZ7DdNnh951g/AtWM5MAfZLczbDjm cZY+c+yKrtqhRLe95qGmVNv4FhQJisXp9X8cdUkNBzl1s0xeBg975VI3IXnCFnyYYgn5 kSaA== X-Gm-Message-State: APjAAAXfF8RUJQOU3iafu9tOlSL7jcNzy/7k7QLm/ieXeAs9DmV1XSeT T1hjh4vq4fzw6aE0L5kmaRo= X-Google-Smtp-Source: APXvYqxYHe0GYT1nhtbgsmRNl6Evg0ScfJ1W1njSxVFPyaocdrWiBczQniX+4YWrw/MkmK2MwCEBUw== X-Received: by 2002:adf:cd8f:: with SMTP id q15mr31912493wrj.21.1574109988793; Mon, 18 Nov 2019 12:46:28 -0800 (PST) Content-Disposition: inline In-Reply-To: <0acc4767-e87f-f163-b39e-f137effdfea2@sbcglobal.net> User-Agent: NeoMutt/20171215 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::432 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: <20191118204626.33smprow5zae4apl@chaz.gmail.com> X-Mailman-Original-References: <0acc4767-e87f-f163-b39e-f137effdfea2.ref@sbcglobal.net> <0acc4767-e87f-f163-b39e-f137effdfea2@sbcglobal.net> Xref: csiph.com gnu.bash.bug:15610 2019-11-17 01:25:31 -0800, Chris Carlen: [...] > # write 'REVERSE PILCROW SIGN' to B, then repeat as above: > printf -v B '\u204B' > set -- ${B//?()/ } > echo "${@@Q}" #-> $'\342' $'\201' $'\213' > > # NOTE: Since there is only one character (under the UTF-8 locale), > # this should have set only the first positional parameter with the > # character REVERSE PILCROW SIGN, not split it into bytes (AFAIK). [...] Yes, the question is where to resume searching after a match of an empty string in ${var//pattern/replacement}. Note that it's even worse in ksh93 where bash copied that syntax from: $ A=$'\u2048\u2048' ksh93 -c 'printf "%q\n" "${A//?()/:}"' $':\u[2048]:\x81:\x88:\u[2048]:\x81:\x88:' (here with ksh93u+) Then there's the question of what ${B/$'\201'/} should do. Should that $'\201' match the byte component of the encoding of U+204B? It seems to me that zsh's approach is best: $ A=$'\u2048\201\u2048' zsh -c "printf '%q\n' \"\${A//$'\201'/:}\"" ⁈:⁈ That is replace that \201 byte, except when it's part of a properly encoded character. Compare with: $ A=$'\u2048\201\u2048' bash -c "printf '%q\n' \"\${A//$'\201'/:}\"" $'\342:\210:\342:\210' $ A=$'\u2048\201\u2048' ksh93 -c "printf '%q\n' \"\${A//$'\201'/:}\"" $'\u[2048]:\x88:\u[2048]:\x88' (or yash which can't deal with that \201 byte at all as it can't form a valid character). -- Stephane