bug-bash
[Top][All Lists]
Advanced

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

Re: How get last commnda history line number directly


From: L A Walsh
Subject: Re: How get last commnda history line number directly
Date: Sun, 06 Sep 2020 13:18:22 -0700
User-agent: Thunderbird

On 2020/09/01 05:32, Greg Wooledge wrote:

On Tue, Sep 01, 2020 at 02:14:33AM -0700, almahdi wrote:

> How to get last commnda history line number?

as it's pure & directly viable in PS1 env. var.
PS1=`echo \!`
---
Doesn't work if you don't have '!' support (I generally found
'!' more often did unwanted things, but I never used csh):
 echo thisline
thisline
 x='\!'; echo "${x@P}"
2993
 history 3
2990  0906@125642:echo thisline
2991  0906@125713:x='\!'; echo "${x@P}"
2992  0906@125721:history 3
---
i.e. it was on line 2990, not 2993


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


On 2020/09/01 06:05, Chet Ramey wrote:
On 9/1/20 5:14 AM, almahdi wrote:
How to get last commnda history line number

HISTCMD
       The history number, or index in the history list, of the current
command.
---
   Seem to need to subtract 2 from that num (is this right?)?
   (in "4.4.12"):

 echo "this is on what history line? ($HISTCMD)"
this is on what history line? (2985)
 echo $(($HISTCMD-2))
2983
history 3
2983  echo "this is on what history line? ($HISTCMD)"
2984  echo $(($HISTCMD-2))
2985  history 3

Seems to only give correct line from history by subtracting 2?
Maybe its different in 5.x?
-l




reply via email to

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