Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Passing History to a variable

Posted on 2002-07-18
5
Medium Priority
?
179 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 200 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 21

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
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…
Suggested Courses

610 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