View Single Post

   
  #6 (permalink)  
Old 02-20-2008, 12:52 PM
Eef Hartman
 
Posts: n/a
Default Re: [OT] A quick bash query > histories

No_One <no_one@no_where.com> wrote:
> if $DISPLAY != ":0.0" parse the tty number one way
> else parse it another way


Better to test on "pts" in the result from "tty", as remote logins
(ssh, rsh, telnet) will also be on pts's (and the latter two do not
have got DISPLAY set by default, ssh will when X-forwarding has been
enabled). So something like
if tty|grep -q "pts"
then HISTFILE=".bash_history-pts`tty|sed "s#/dev/pts/##"`
else HISTFILE=".bash_history-tty`tty|sed "s#/dev/tty##"`
fi
will probably work.

As far as I known the old pty's (pseudo terminals, sort of a predecessor
to pts streams) aren't used anymore, but if you want to make sure,
you could add an extra test for those:
elif tty|grep -q "pty"
then HISTFILE=".bash_history-pty`tty|sed "s#/dev/pty##"`
(before the "else" in the above condition).

But by then it is probably useful to run "tty" just once and store
the result, instead of keeping on invoking it.
--
************************************************** ******************
** Eef Hartman, Delft University of Technology, dept. EWI/TW **
** e-mail: E.J.M.Hartman@math.tudelft.nl, fax: +31-15-278 7295 **
** snail-mail: P.O. Box 5031, 2600 GA Delft, The Netherlands **
************************************************** ******************
Reply With Quote