help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Input history when using read


From: Suvayu Ali
Subject: Re: [Help-bash] Input history when using read
Date: Tue, 5 Feb 2013 16:03:58 +0100
User-agent: Mutt/1.5.21 (2011-07-01)

Hello Matthew,

On Tue, Feb 05, 2013 at 11:36:08PM +1100, Matthew Cengia wrote:
> On 2013-02-05 13:00, Suvayu Ali wrote:
> > Hi,
> > 
> > I have a script that searches through emails for me.  I read in my
> > search query either as positional parameters or read.  Often I want to
> > repeat a variation of a complicated search.  I was wondering if it is
> > possible to have some sort of history when I get the query using read.
> > This is what I have so far:
> > 
> 
> Try this:
> 
>   address@hidden:tmp$ cat muttsearch
>   #!/bin/bash -ueE
>   # Allocate new history file and delete it on exit.
>   export HISTFILE=~/.mutt_search_history
>   if [[ ! -e $HISTFILE ]]; then
>     touch "$HISTFILE"
>   fi
> 
>   history -c                      # Clear all current history.
>   history -n                      # Read everything from history file.
>   read -ep "Search query: " query
>   echo "$query" >> "$HISTFILE"
>   address@hidden:tmp$
> 
> It makes use of existing readline features, allowing you to store stuff
> in history, and search it with up/down arrows, as well as Ctrl+P/N/R/I.
> I'm not sure whether there's a better way to append to the history file
> than the echo above; hopefully somebody else can improve on that.
> 

This works beautifully!  I'll adapt this to my script.  Thanks a lot.

-- 
Suvayu

Open source is the future. It sets us free.



reply via email to

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