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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/