Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.unix.shell Subject: Re: [ksh] Show command number in shell prompt Date: Tue, 24 Sep 2024 13:01:47 -0700 Organization: None to speak of Lines: 51 Message-ID: <87jzf0q0r8.fsf@nosuchdomain.example.com> References: MIME-Version: 1.0 Content-Type: text/plain Injection-Date: Tue, 24 Sep 2024 22:01:47 +0200 (CEST) Injection-Info: dont-email.me; posting-host="cfe9758cda96ae01dcefed05ed131451"; logging-data="3495475"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MV0gIDHoV68n6XBQR+VVp" User-Agent: Gnus/5.13 (Gnus v5.13) Cancel-Lock: sha1:VCtug+nanoMMGZmUoDLfmZcqwfk= sha1:CdiHy5/QeqnrQIYktYBFJh24llg= Bytes: 3344 hymie! writes: > In our last episode, the evil Dr. Lacto had captured our hero, > Janis Papanagnou , who said: >> On 24.09.2024 14:59, hymie! wrote: >>> In our last episode, the evil Dr. Lacto had captured our hero, >>> Janis Papanagnou , who said: >>>> Not long ago I added an '!' (exclamation mark) to my prompt to have >>>> it get expanded to the command number [in Kornshell]; PS1='(!)$ ' >>>> The effect is that a new shell instance starts with the number 1000 >>>> which incidentally equals the HISTSIZE. - Any ideas what could have >>>> gone wrong here? >>> >>> Nothing has gone wrong. >>> >>> HISTSIZE=1000 means that the maximum size of your history is 1000. Once it >>> hits that level, the oldest entries are dropped, and the newest entries >>> are added to the end. >>> >>> So every command you issue is always the last command in the history. >>> Since the history is full, it's always command number 1000. >> >> Hmm.. - that explains, maybe, part of it. Thanks. >> >> I'm still irritated; if I see in one shell session a value of 11059 >> (which is an indication that the numbers created by '!' don't wrap) >> I'm astonished that the counting in a new window will start at 1000 >> (and not at 1 or at the maximum previous value). > > I don't use this feature, and I don't have ksh, just bash and zsh. > Bash has separate options for > > \! the history number of this command > \# the command number of this command > > I don't know what your goal is, but maybe ksh has these two options, and you > want the other one? > > For the record, every time I open a bash shell, \! starts at 51 (HISTSIZE + 1) > and \# starts at 1. If you use numbered history references, they refer to the history number, not the command number. For example, !25 will execute the 25th command from your history. This could be confusing if you show the command number in $PS1. I didn't know about \# until just now. I've just updated my .bashrc to put "\#/\!" in my $PS1. I suspect I won't find it useful. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com void Void(void) { Void(); } /* The recursive call of the void */