3
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?
3
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?
3
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 – 2014-02-03T13:24:58.370