LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-04-2011, 04:24 AM   #1
swingliner
LQ Newbie
 
Registered: Oct 2010
Posts: 10

Rep: Reputation: 2
Bash: run a hook after each command?


Is it possible to run a post-command hook? I want to put what would end up in my .bash_history file into an sqlite database along with meta-info like process ID and timestamp, so that I can keep track of different shell histories. (I routinely have dozens of shells open).

Last edited by swingliner; 11-04-2011 at 04:28 AM.
 
Old 11-04-2011, 04:45 AM   #2
serafean
Member
 
Registered: Mar 2006
Location: Czech Republic
Distribution: Gentoo, Chakra
Posts: 997
Blog Entries: 15

Rep: Reputation: 136Reputation: 136
Hi,
Every time bash finishes a command, it regenerates the prompt. You can modify this function by setting the PROMPT_COMMAND=my_command, and then you can define my_command to do what you want. Example :
Code:
function prompt {
if [[ $? -gt 0 ]];then
·       echo "worked"
else
·       echo "Didn't work"
fi
}

PROMPT_COMMAND=prompt
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash: run command in new tty action_owl Programming 4 06-03-2012 09:00 PM
[SOLVED] Partial list with ls-l in bash script run in cron but full list run from command line redgshost Linux - General 29 01-16-2011 12:14 PM
getting php to run a bash command kitesurfa Programming 1 06-30-2010 02:58 PM
Bash Command Line Editor, while typing run another command before executing current? gumaheru Linux - General 5 04-13-2010 11:21 AM
BASH: run command with parameters from variable Roger Krowiak Programming 3 10-30-2007 03:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:11 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration