🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #4009

Re: Get previous command history number from a script

#4009
From: hanzhengxu
Date: Wed, 03 Jun 2009 09:10
16 lines
2013 bytes
On Jun 3, 3:44 pm, Ben <bgol...@gmail.com> wrote:
> I've already figured out a way to do this but I suspect there are
> simpler/faster/more elegant solutions that exist.
>
> The objective is to get the command history number of the command that
> was just executed, but do it from a script (which seems to prevent
> access to the $HISTCMD variable, which would've been nice; any
> thoughts on this?). Here's my solution:
>
> history 2| sed -n 1p| sed -e "s/^\s*\([0-9]\+\).*/\1/";
>
> Notice the (command complexity) / (problem complexity) ratio. Can
> anyone improve it?

Any good usages for history number in scripts?
It seems should use 'set -o history' to enable history in a script.
Technical Details
Message-ID: <e207a0ea-21ea-4e35-bc1f-ff622510d6b1@q2g2000vbr.googlegroups.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!q2g2000vbr.googlegroups.com!not-for-mail
References: <aa76cb4f-d625-49fb-9d0b-5480001cfd1e@q37g2000vbi.googlegroups.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 4d82dd0a1,5ff149a7a3349cd6
X-Google-Attributes: gid4d82dd0a1,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,ASCII
Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!q2g2000vbr.googlegroups.com!not-for-mail
From: hanzhengxu@gmail.com
Newsgroups: comp.unix.shell,comp.unix.programmer,gnu.bash
Subject: Re: Get previous command history number from a script
Date: Wed, 3 Jun 2009 02:10:12 -0700 (PDT)
Organization: http://groups.google.com
Lines: 16
Message-ID: <e207a0ea-21ea-4e35-bc1f-ff622510d6b1@q2g2000vbr.googlegroups.com>
References: <aa76cb4f-d625-49fb-9d0b-5480001cfd1e@q37g2000vbi.googlegroups.com>
NNTP-Posting-Host: 60.247.97.97
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1244020212 31186 127.0.0.1 (3 Jun 2009 09:10:12 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 3 Jun 2009 09:10:12 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: q2g2000vbr.googlegroups.com; posting-host=60.247.97.97; 
 posting-account=mPK1lgoAAAC2InnpBjZVpJULyT8ImpLN
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) 
 Gecko/2009042708 Fedora/3.0.10-1.fc10 Firefox/3.0.10,gzip(gfe),gzip(gfe)