[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Readline history and bash's read -e
From: |
Mike Stroyan |
Subject: |
Re: Readline history and bash's read -e |
Date: |
Sun, 2 Sep 2007 16:36:20 -0600 |
User-agent: |
Mutt/1.5.13 (2006-08-11) |
On Sat, Sep 01, 2007 at 12:11:58AM +0100, 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?
Phil,
You can use "history -r" to read a file into the shell's history
and "history -s" to add each line that you read into the history.
Then use history -w to save the history back to the file. Here is
an example with vi style readline editing.
#!/bin/bash
history -r script_history
set -o vi
CMD=""
while true
do
echo "Type something"
read -e CMD
history -s "$CMD"
echo "You typed $CMD"
case "$CMD" in
stop)
break
;;
history)
history
;;
esac
done
history -w script_history
echo stopping
--
Mike Stroyan <mike@stroyan.net>