On 2024-01-13, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Is there a possibility to somehow get readline(3) editing support
into such a read loop, so that whenever the prompt is displayed I
can skim (e.g. with cursor keys) through the previous data input?
If not in ksh; is that maybe possible in bash or zsh ?
Not in bash, where "read -e" will use readline(3), but it doesn't
keep any history, so you can't access previous input.
In article <slrnuq546h.20hn.naddy@lorvorc.mips.inka.de>,
Christian Weisgerber <naddy@mips.inka.de> wrote:
On 2024-01-13, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Is there a possibility to somehow get readline(3) editing support
into such a read loop, so that whenever the prompt is displayed I
can skim (e.g. with cursor keys) through the previous data input?
If not in ksh; is that maybe possible in bash or zsh ?
Not in bash, where "read -e" will use readline(3), but it doesn't
keep any history, so you can't access previous input.
No idea what you're on about here. It works as expected for me.
Not in bash, where "read -e" will use readline(3), but it doesn't
keep any history, so you can't access previous input.
No idea what you're on about here.
On 2024-01-13, Kenny McCormack <gazelle@shell.xmission.com> wrote:
Not in bash, where "read -e" will use readline(3), but it doesn't
keep any history, so you can't access previous input.
No idea what you're on about here.
What I said.
Anybody can try it for themselves:
while IFS= read -r -e -p "prompt> " line
do
echo "[$line]"
done
Actually, the lack of history is only true if you run it in a script.
In an interactive shell, there is history--but it's the command
history and it does not include the "read" input.
That would be okay (at least for ksh) since ksh's 'read -s' allows to
drop the read input to the command history.
#!/usr/local/bin/bash -i
while IFS= read -r -e -p "prompt> " line
do
echo "[$line]"
history -s "$line"
done
On 2024-01-14, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
That would be okay (at least for ksh) since ksh's 'read -s' allows to
drop the read input to the command history.
Bash also has a way to push commands into history. And in an
_interactive_ shell, "read -e" has access to history. Also, it
looks like the loop is considered a single command. We can combine
all this:
#!/usr/local/bin/bash -i
while IFS= read -r -e -p "prompt> " line
do
echo "[$line]"
history -s "$line"
done
It seems fragile, though, depending on underspecified behavior.
And I lack an understanding of the consequences of forcing a shell
to run as if interactive when executing a script.
This works for me. It's the stripped down version of a couple of scripts
I use every login session ...
#!/bin/bash
HISTFILE=$HOME/.history.test
HISTNUM=200
while $loop ; do
echo
set -H -o history
history -r
read -p "prompt : " -e ans
echo "$ans" >> $HISTFILE
case "$ans" in
q|quit|Q|Quit|QUIT)
exit 0
;;
esac
done
HTH
Jim
This works for me. It's the stripped down version of a couple of scripts
I use every login session ...
#!/bin/bash
HISTFILE=$HOME/.history.test
HISTNUM=200
while $loop ; do
echo
set -H -o history
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 365 |
Nodes: | 16 (3 / 13) |
Uptime: | 25:07:21 |
Calls: | 7,748 |
Calls today: | 2 |
Files: | 12,888 |
Messages: | 5,740,139 |
Posted today: | 1 |