• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

history command question

 
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.
 
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.
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!