Solved

Passing History to a variable

Posted on 2002-07-18
5
170 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
Comment Utility
var=`history -n|head -1`
echo $var
0
 

Author Comment

by:Randy2001
Comment Utility
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
Comment Utility
it's useless without quotes.
and you (probably) used quotes, but I posted backticks !!
0
 
LVL 20

Expert Comment

by:tfewster
Comment Utility
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
Comment Utility
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

763 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

7 Experts available now in Live!

Get 1:1 Help Now