bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Readline history and bash's read -e


From: Chet Ramey
Subject: Re: Readline history and bash's read -e
Date: Sun, 02 Sep 2007 18:43:04 -0400
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

Phil Endecott wrote:
> Dear Bash and Readline Experts,
> 
> I have a simple shell script that reads user commands in a loop using
> "read -e".  -e enables readline, but not its history feature.  Is there
> any way to get readline history with bash's read builtin?

Sure.  You can do it entirely with bash builtins and shell variables.

> I wouldn't want to get the user's regular bash history; rather, this
> program would need its own history file in the user's home directory.
> For example:
> 
> read -e --historyfile=~/.myprogname_history CMD

HISTFILE=~/.myprogram_history
history -r

(The `history -r' is needed if you'd like history to persist across
program invocations.)

To save the lines read to the history list, use `history -s':

read -e CMD
[ -n "$CMD" ] && history -s "$CMD"

If at the end of the script you'd like to save the history to the
history file, use `history -w' or `history -a'.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                       Live Strong.  No day but today.
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]