• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

history command question

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the information. I did not know that about bash.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic