Re: bash v. ksh history

Go to solution
A. Daniel King_1
Super Advisor

bash v. ksh history

Hi, folks.

From the bash man page, I see:

If set, the history list is appended to the file named by the value of the HISTFILE variable when the shell exits, rather than overwriting the file.

Q: Is there a way to make bash history save immediately upon execution, like HP-UX ksh, instead of upon exit?

Thanks, all.
Command-Line Junkie
Abdul Rahiman
Esteemed Contributor

Re: bash v. ksh history

I think that's how the bash_history file works. A work around would be to run the 'history -w' command time-to-time manually to write the history to the history file.
May be you can automate this somehow to achieve the desired result.

No unix, no fun
Honored Contributor

Re: bash v. ksh history


bash shell is more efficient and effective that korn shell. It is a advanced one and a superset of all shells.

By default, history command will add the history of commans to $HISTFILE ( $HOME/.bash_history)

You can view the view or execute as #history with out any argument.

bash will store the history of commands upong execution. You can know it as,
# history | tail -10
you will see the history | tail -10 in the list.

If you want to overrite the history file then use history -w or set the histappend shell variable as 1 in .bash_profile file.

Easy to suggest when don't know about the problem!
Steven E. Protter
Exalted Contributor

Re: bash v. ksh history

I've noticed there is a lag in updating the .bash_history file.

For example

Two root sessions open:

do a few commands in session 1.

go to session 2 and those commands are not available in session 2.

It gets annoying. I've played with this for some time but not been able to get immediate update.

Steven E Protter
Owner of ISN Corporation
A. Daniel King_1
Super Advisor

Re: bash v. ksh history

export PS1='$(history -w)\w\$ '

Did a near enough approximation.

Thanks all!
Command-Line Junkie