Article View: comp.unix.shell
Article #4008Get previous command history number from a script
From: Ben
Date: Wed, 03 Jun 2009 07:44
Date: Wed, 03 Jun 2009 07:44
12 lines
1758 bytes
1758 bytes
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?
Technical Details
Message-ID:
<aa76cb4f-d625-49fb-9d0b-5480001cfd1e@q37g2000vbi.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!q37g2000vbi.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 4d82dd0a1,5ff149a7a3349cd6,start X-Google-Attributes: gid4d82dd0a1,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news2.google.com!postnews.google.com!q37g2000vbi.googlegroups.com!not-for-mail From: Ben <bgold12@gmail.com> Newsgroups: comp.unix.shell,comp.unix.programmer,gnu.bash Subject: Get previous command history number from a script Date: Wed, 3 Jun 2009 00:44:04 -0700 (PDT) Organization: http://groups.google.com Lines: 12 Message-ID: <aa76cb4f-d625-49fb-9d0b-5480001cfd1e@q37g2000vbi.googlegroups.com> NNTP-Posting-Host: 99.237.202.239 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1244015044 28760 127.0.0.1 (3 Jun 2009 07:44:04 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 3 Jun 2009 07:44:04 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: q37g2000vbi.googlegroups.com; posting-host=99.237.202.239; posting-account=dZduOQoAAAAyiZ2odBLj6MlasZbptZ8w User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.65 Safari/525.19,gzip(gfe),gzip(gfe)