Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How get last commnda history line number directly

5 views
Skip to first unread message

almahdi

unread,
Sep 1, 2020, 5:14:49 AM9/1/20
to Bug-...@gnu.org
How to get last commnda history line number purely & directly on bash script
or prompt ?

as it's pure & directly viable in PS1 env. var.
PS1=`echo \!`

confusingly bash 'mainstream' itself wasn't found way to do




--
Sent from: http://gnu-bash.2382.n7.nabble.com/

Greg Wooledge

unread,
Sep 1, 2020, 8:32:57 AM9/1/20
to bug-...@gnu.org
On Tue, Sep 01, 2020 at 02:14:33AM -0700, almahdi wrote:
> How to get last commnda history line number purely & directly on bash script
> or prompt ?
>
> as it's pure & directly viable in PS1 env. var.
> PS1=`echo \!`
>
> confusingly bash 'mainstream' itself wasn't found way to do

unicorn:~$ x='\!'; echo "${x@P}"
590

I don't know how you plan to *use* this, though. It sounds like an X-Y
problem to me.

Chet Ramey

unread,
Sep 1, 2020, 9:05:31 AM9/1/20
to almahdi, Bug-...@gnu.org, chet....@case.edu
On 9/1/20 5:14 AM, almahdi wrote:
> How to get last commnda history line number purely & directly on bash script
> or prompt ?
>
> as it's pure & directly viable in PS1 env. var.
> PS1=`echo \!`

HISTCMD
The history number, or index in the history list, of the current
command. Assignments to HISTCMD are ignored. If HISTCMD is un-
set, it loses its special properties, even if it is subsequently
reset.

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

0 new messages