bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: \! and \# in PS1 vs PS2 vs PS4, PS0 and ${var@P}


From: Chet Ramey
Subject: Re: \! and \# in PS1 vs PS2 vs PS4, PS0 and ${var@P}
Date: Tue, 14 Mar 2017 21:07:36 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.7.1

On 3/12/17 5:06 PM, Grisha Levit wrote:
> These expansions both seem to get values that are inconsistent when
> expanded in the various prompt strings.
> 
> For example, starting with the following:
> 
> PS0='PS0 \! \# _ \n'
> PS1='PS1 \! \# $ '
> PS2='PS2 \! \# > '
> PS4='PS4 \! \# + '
> PSV='PSV \! \# V '
> set -x
> 
> The prompts evaluate like so:
> 
> PS1 529 45 $ echo \
> PS2 530 45 > ${PSV@P}
> PS0 530 46 _
> PS4 530 46 + echo PSV 530 46 V
> PSV 530 46 V
> PS1 530 46 $
> 
> i.e. \! is increased as soon as the first line is read, even though
> the subsequent line(s) are to become part of the history entry
> associated with the number displayed in PS1.

I'm not sure what the question is.  It seems reasonable to assume that
when PS1 is expanded the first time, the "current" history entry is the
one corresponding to the last command entered -- nothing has been
entered that would start a new history entry, and the counter doesn't
work ahead like that.

When the first line is entered, the history number and command numbers
get incremented; that's going to be the next (the new "current") history
entry.  PS2 looks at the current history entry, which is 530 since we've
started on it. PS0 and PS4 get 530 because they get expanded after the
complete command is entered and the history entry "finalized", and before
any new history entry is started.

When PS1 is expanded before the next command is read, the situation is
the same as in the first paragraph.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]