Solved

Passing History to a variable

Posted on 2002-07-18
5
175 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 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 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nodeip 9 92
AIX check for filesystems not mounted but mount = true 4 42
aix tls version 6 557
UNIX Script. Send email if failure 8 65
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

726 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