[NTLUG:Discuss] HOW? bash shell shortcut using history|grep

Chris Cox cjcox at acm.org
Thu Jun 7 12:33:17 CDT 2001


Short answer: No.. two live shells should not collide.

...and in the more answer than I really wanted to know dept..

The bash manpage details it pretty well.  If HISTFILE is set,
then your history is saved at the time the shell exits 
and typically the file that is used by default
is .bash_history.  The last HISTSIZE lines are written out
which defaults to 500 if not specified.  Normally the file
is truncated to HISTSIZE on read-in and HISTSIZE lines are
written out at the end of session... which seems to imply
that at the end, the file could contain more than HISTSIZE lines
if configured to append the lines instead of overwriting them
(see the histappend shell option).

Make NO ASSUMPTIONS on this, since much of the control is
intended to be in the user's hands.  That means he could
easily setup HISTFILE to use the current PID in it's naming
so that each session is uniquely saved after they are
ended, etc. (a kazillion of different ways of doing this..
for example, could use the tty somehow in the file name...whatever).

As for the fear of sharing history sessions, you don't have to
worry about two live sessions colliding with each other.
However, if the same HISTFILE is used for all sessions, the
last one to exit takes precedence on the next shell
started... though hopefully you will not rely on the
history from a former session.  For security reasons, it's
probably not wise to leave a HISTFILE around anyway (though
I realize that is an inconvenience to many).

If you are about to do something with the shell and want
to remember everything that was done, you may want
to look at the "script" command and see if that doesn't
do what you really wanted.

Regards,
Chris


MadHat wrote:
> 
> At 08:46 AM 6/7/2001 -0500, you wrote:
> >Something that has always puzzled me about the shell history
> >file:   If a user is logged in on multiple tty's, does the
> >users history from all sessions go into the same file?  This
> >could be a real problem if I do a !r hoping to envoke rpm but
> >someone else using the same login just did an rm -rf *
> 
> yes and no on the history file...  yes it using the same history file, but
> it is written to after log out, so if you log in on one tty, that history
> is read from the file and held and modified in memory (I believe, it might
> be a tmp file).  The second tty you connect with will ready the same file
> and have the same history as the first, until a command is run.  if one
> logs out, their updated history is written back to the history file, but I
> am not sure if it uses the history it has in memory, or if it just adds on
> to the end...  haven't looked... now I need to go look that up, or it will
> bother me for days.  I'll get back to you, unless someone else knows already.
> 
> >George
> >_______________________________________________
> >http://www.ntlug.org/mailman/listinfo/discuss
> 
> --
> MadHat at unspecific.com
> 
> "Focus on the packet.  It's better that way."
>                                               -tb
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss



More information about the Discuss mailing list