Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to write an interactive command shell in shell script, for easier adjusting of the iptables firewall. The problem is, that read -e uses the shell history. Is there a way of using a separate history for read -e in a script?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If you have rlwrap (debian package rlwrap), then you could use something like:

LINE=$(rlwrap head -n1)

which will use the file ~/.head_history by default. (man rlwrap for more details, including options for specifying a history filename.)

Another possibility is to run read in a subshell with HISTFILE set to your own history file, but you'll need to do a lot more work because although read -e uses the history, it does not update it. So you'll probably need something like:

LINE=$(bash -c 'HISTFILE=/path/to/history_file;
                history -r; read -e LINE;
                history -s "$LINE"; history -w;
                echo "$LINE")
share|improve this answer
    
Yes!! I have rlwrap. It is already installed on my Fedora 20 installation. It works! –  BenjiWiebe Feb 3 at 13:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.