[Toybox] One more bash corner case.

Chet Ramey chet.ramey at case.edu
Sat Dec 14 10:32:28 PST 2024


On 12/14/24 8:30 AM, Rob Landley wrote:
> In devuan deadmaus, which claims bash --version 5.2.15(1)-release (x86_64- 
> pc-linux-gnu) when I do:
> 
> echo -e 'echo \n' | env -i PATH=${PATH at Q} PS1='\\$ ' bash --noediting -- 
> noprofile --norc -is
> 
> It prints $ three times instead of printing \$ three times. But when I add 
> -c 'echo $PS1' it says "\\$" which has both slashes. (Which makes sense 
> because single quotes, above...)
> \\
> The man page says \\ is a literal backslash, but it's not printing.

OK, think about this in terms of all the expansions for PS1.

First, it expands \\$ because of the \\ prompt expansion, leaving \$
when that phase is complete.

Then, after expanding the backslash-escape sequences,

"After the  string  is
  decoded,  it is expanded via parameter expansion, command substitution,
  arithmetic expansion, and quote removal, subject to the  value  of  the
  promptvars shell option"

Since promptvars is enabled by default, quote removal removes the
backslash, leaving `$ '.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet at case.edu    http://tiswww.cwru.edu/~chet/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20241214/a5899026/attachment.sig>


More information about the Toybox mailing list