Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

history command question

 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 443
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 11878
195
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the information. I did not know that about bash.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic