aspose file tools*
The moose likes Linux / UNIX and the fly likes history command question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "history command question" Watch "history command question" New topic
Author

history command question

kevin comario
Ranch Hand

Joined: Jun 29, 2002
Posts: 65
Can I execute the history command in a bash script? If so could you tell me how so far I have been unsuccessful to do so.
Alton Hernandez
Ranch Hand

Joined: May 30, 2003
Posts: 443
Originally posted by kevin comario:
Can I execute the history command in a bash script? If so could you tell me how so far I have been unsuccessful to do so.

Yes, why not? It's just like any shell script command.
What errors are you getting ?
kevin comario
Ranch Hand

Joined: Jun 29, 2002
Posts: 65
When I use the history command in a bash file it doesnt list anything. So i tried redirecting it to a temp file, and still nothing. Can an admin turn off such a function? Also I am using red hat if that makes a diffrence.
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11526
    
100

Hi Kevin,
I dont think your problem is due to RedHat, rather it is due to bash's history function.
By default, bash only enables history for interactive shells. Running a script does not fall under that category.
You can turn history on in the script by using the <code>set -o history</code> command in your script.
Your next problem (or security feature) is that the history you get will then be for that particular shell. You will not get a history for commands the user has typed. This is generally a good thing.
The following script works on my system:

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
kevin comario
Ranch Hand

Joined: Jun 29, 2002
Posts: 65
Thank you for the information. I did not know that about bash.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: history command question