Solved

Passing History to a variable

Posted on 2002-07-18
5
171 Views
Last Modified: 2010-04-21
If I were to type history -n at the command prompt I would get a list of recent commands that have been typed.  

I need to trap the first command in the list and pass it to a variable where I can use it as I please.

How do I do this?

Thanks in advance!
0
Comment
Question by:Randy2001
5 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 50 total points
ID: 7163325
var=`history -n|head -1`
echo $var
0
 

Author Comment

by:Randy2001
ID: 7164950
Thanks.  I tried it as you have it and without the quotes and for some reason it is not working.  

Here is what is in my script:

#!/bin/sh

var='history -n|head -1'
echo $var

Here is the output:

history -n|head -1


I took the quotes of out of the script and got this:

-n: not found
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7164966
it's useless without quotes.
and you (probably) used quotes, but I posted backticks !!
0
 
LVL 20

Expert Comment

by:tfewster
ID: 7921600
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by ahoffmann

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 7967222
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now