On 12/14/24 12:32, Chet Ramey wrote:
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@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.

If by "it" you mean "the prompt logic", then yes that's what I expected.

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 `$ '.

Aha: the "promptvars" option gratuitously expands PS1 _twice_:

$ touch potato
$ PS1='$(rm potato)' bash --noprofile --norc
exit
exit
$ ls -l potato
ls: cannot access 'potato': No such file or directory

And you default it to on. Good to know.

Rob
_______________________________________________
Toybox mailing list
Toybox@lists.landley.net
http://lists.landley.net/listinfo.cgi/toybox-landley.net

Reply via email to