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?

1 Answer 1


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"')
  • Yes!! I have rlwrap. It is already installed on my Fedora 20 installation. It works!
    – BenjiWiebe
    Feb 3, 2014 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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