This is a discussion on Re: ksh diff, part II within the mailing.openbsd.tech forums, part of the OpenBSD category; --> On Tue, 23 May 2006, Marcus Glocker wrote: > On Tue, May 23, 2006 at 09:07:04PM +0200, Otto Moerbeek ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Tue, 23 May 2006, Marcus Glocker wrote: > On Tue, May 23, 2006 at 09:07:04PM +0200, Otto Moerbeek wrote: > > > Care to explain? For PS1, posix describes: > > > > "PS1 Each time an interactive shell is ready to read a command, the value > > of this variable shall be subjected to parameter expansion and written > > to standard error." > > "2.2.3 Double Quotes > The backslash shall retain its special meaning as an escape character > only when followed by one of the following characters when > considered sepcial: > $ ` " \ <newline>" > > PS1="$x$(print \\r)$x$(tput so)$x\$PWD$x$(tput se)$x> " > > In my understanding escaping \$PWD in double quotes should result > in $PWD because $ got escaped and looses its meaning as a variable > holder. So I would assume to just set $PWD in double quotes, which > still works with my diff applied. But how exactly? The example puts the current wd in the prompt. Let's use a more simple example with the current ksh: PS1="\$PWD " there are two moments variable substitution takes place. The first is when assigning to PS1. The \ is needed to avoid immediate expansion of $PWD, since you want to do that each time a new prompt is displayed, the piece from posix I quoted earlier says that should be done each time a prompt is displayed. So after assigning PS1, it holds the string '$PWD ', which will be expanded each time a prompt is printed and so have the desired effect of printing the current wd. With your diff, the expansion will be done only once, on the initial assignment of PS1. I do not see how you'd get the current working dir in a prompt with your diff. And what's more, I do not see how the current behaviour is non-posix, as you claim. -Otto |