Link to home
Start Free TrialLog in
Avatar of Randy2001
Randy2001

asked on

Passing History to a variable

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!
ASKER CERTIFIED SOLUTION
Avatar of ahoffmann
ahoffmann
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Randy2001
Randy2001

ASKER

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
it's useless without quotes.
and you (probably) used quotes, but I posted backticks !!
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
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange