Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 26 |
Nodes: | 6 (1 / 5) |
Uptime: | 18:43:11 |
Calls: | 629 |
Files: | 1,186 |
D/L today: |
19 files (29,897K bytes) |
Messages: | 167,605 |
Searching for 'getkey' functions I stumbled across https://linux.die.net/man/1/getkey
getkey(1) - Linux man page
Name getkey - wait until a key is pressed
Synopsis getkey [OPTION]... [KEYS]
But that's not available on my Linux systems.
Where is that obtainable from, or is that a hoax?
Searching for 'getkey' functions I stumbled across >https://linux.die.net/man/1/getkey
getkey(1) - Linux man page
Name getkey - wait until a key is pressed
Synopsis getkey [OPTION]... [KEYS]
But that's not available on my Linux systems.
Where is that obtainable from, or is that a hoax?
Debian doesn't provide it.
You could write a shell function or C/python/awk/pascal/....
program that mimics it.
Searching for 'getkey' functions I stumbled across https://linux.die.net/man/1/getkey
getkey(1) - Linux man page
Name getkey - wait until a key is pressed
Synopsis getkey [OPTION]... [KEYS]
But that's not available on my Linux systems.
Where is that obtainable from, or is that a hoax?
https://github.com/glensc/rc-scripts/blob/master/src/getkey.c
On 9/21/25 16:33, Janis Papanagnou wrote:
Searching for 'getkey' functions I stumbled across
https://linux.die.net/man/1/getkey
Here's the man page for the specs:
https://linux.die.net/man/1/getkey
On 21.09.2025 17:23, Kees Nuyt wrote:
On 9/21/25 16:33, Janis Papanagnou wrote:
Searching for 'getkey' functions I stumbled across
https://linux.die.net/man/1/getkey
Here's the man page for the specs:
https://linux.die.net/man/1/getkey
Funny response (given my post).
In article <10ap2ci$1pgnr$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Searching for 'getkey' functions I stumbled across[...]
https://linux.die.net/man/1/getkey
[...]
But that's not available on my Linux systems.
Anyway, I assume if you were willing to dig, you could find source code for it somewhere.
FWIW, it didn't come up in a repo search of either of the
two Linux systems I just checked.
As it happens, a zillion or so years ago, I wrote a utility (in C) called "pause" that was based (loosely) on the functionality of the DOS/Windows command of the same name. At that time, there was no built-in way to do
it on Unix. I still use my "pause" in my scripts to this day.
Nowadays. you can use "read -sn1" in bash or ksh. I've used it on bash,
and I just now checked that (at least the ksh on this system) it works on ksh, too.
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Searching for 'getkey' functions [...]
OK, I found it like this.
On GitHub, I searched for the man page using a source code
search for "path:getkey.1".
Among the results, that led to this project which contains
the man page, and provides C program implementing it:
https://github.com/glensc/rc-scripts/blob/master/src/getkey.c
[...]
Nowadays. you can use "read -sn1" in bash or ksh. I've used it on bash,
and I just now checked that (at least the ksh on this system) it works on
ksh, too.
I doubt it's in ksh (as advertised here); '-s' feeds the history.
On 21.09.2025 18:29, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Searching for 'getkey' functions [...]
OK, I found it like this.
On GitHub, I searched for the man page using a source code
search for "path:getkey.1".
Among the results, that led to this project which contains
the man page, and provides C program implementing it:
https://github.com/glensc/rc-scripts/blob/master/src/getkey.c
I have a problem with that code; it refers to a "popt.h" that leads
to a fatal error when compiling a git clone of that package. (I'm
reluctant to start invest time in projects of this type of quality.
I suppose it's easier to "re-invent" my own tool. *sigh*)
I haven't thought that there would be problems to find some standard
tool. But, OTOH, I had noticed that I already asked for such function
some time ago and also didn't find some "standard" tool. Also on the
Net (where some other folks had also asked for such tools over time)
they often got just snippy responses, and no suggestions. - It seems
to be a hard (or unworthy) request. :-)
In article <10apenm$1squ0$1@dont-email.me>,[...]
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
...
Nowadays. you can use "read -sn1" in bash or ksh. I've used it on bash, >>> and I just now checked that (at least the ksh on this system) it works on >>> ksh, too.
I doubt it's in ksh (as advertised here); '-s' feeds the history.
You could have just tried this on your ksh instead of complaining that it would not work.
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
[...]
Quick proof-of-concept bang-up:
getkey()
{
local save=$(stty -g)
stty raw -echo
local char=$(dd bs=1 count=1 2> /dev/null)
stty $save
printf "%s" "$char"
}
key=$(getkey)
On 21.09.2025 21:02, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
[...]
Quick proof-of-concept bang-up:
getkey()
{
local save=$(stty -g)
stty raw -echo
local char=$(dd bs=1 count=1 2> /dev/null)
stty $save
printf "%s" "$char"
}
key=$(getkey)
This looks very much like the function I've written for ksh
(in my various tries of all sorts of variants)... :-)
f_getkey () {
stty_g=$( stty -g ) # save state
stty -echo raw
dd bs=1 count=1 2> /dev/null
stty "${stty_g}" # restore state
}
On 2025-09-22, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
This looks very much like the function I've written for ksh
(in my various tries of all sorts of variants)... :-)
We were both trained on the same data set, so we predict
about the same tokens.
f_getkey () {
stty_g=$( stty -g ) # save state
stty -echo raw
dd bs=1 count=1 2> /dev/null
stty "${stty_g}" # restore state
}
Why I don't quote the variable holding stty -g settings is that
POSIX requires it not to require quoting.
read -n 1 -s -r -p "Press any key to continue..."
Why I don't quote the variable holding stty -g settings is that
POSIX requires it not to require quoting.
(BTW, "requires to not require" is a noteworthy formulation.)
What's the reason for that POSIX non-requirement?
On 21.09.2025 21:02, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
[...]
Quick proof-of-concept bang-up:
getkey()
{
local save=$(stty -g)
stty raw -echo
local char=$(dd bs=1 count=1 2> /dev/null)
stty $save
printf "%s" "$char"
}
key=$(getkey)
This looks very much like the function I've written for ksh
(in my various tries of all sorts of variants)... :-)
f_getkey () {
stty_g=$( stty -g ) # save state
stty -echo raw
dd bs=1 count=1 2> /dev/null
stty "${stty_g}" # restore state
}
Another suggestion, to use 'read -n1', maybe in the form of
read -r -t0 -n1
might already suffice, and being a built-in it may be faster.
(The timer -t0 setting is nice for polling.)
Janis
On 21.09.2025 21:02, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
[...]
Quick proof-of-concept bang-up:
getkey()
{
local save=$(stty -g)
stty raw -echo
local char=$(dd bs=1 count=1 2> /dev/null)
stty $save
printf "%s" "$char"
}
key=$(getkey)
This looks very much like the function I've written for ksh
(in my various tries of all sorts of variants)... :-)
f_getkey () {
stty_g=$( stty -g ) # save state
stty -echo raw
dd bs=1 count=1 2> /dev/null
stty "${stty_g}" # restore state
}
Another suggestion, to use 'read -n1', maybe in the form of
read -r -t0 -n1
might already suffice, and being a built-in it may be faster.
(The timer -t0 setting is nice for polling.)
Janis
On 22/09/2025 at 01:42, Janis Papanagnou wrote:
On 21.09.2025 21:02, Kaz Kylheku wrote:
[snip][anip]
Strikes me neither of these functions do what is described in the getkey manual page (above) which was select a keypress from a list, return 0 if
in list, 1 if not in list.
My suggestion (bash):
getkey ()
{
local R S;
(($#==0)) || {
# remove spaces
S="$*";
S="${S// /}";
S="${S,,}";
S+="${S^^}"
};
read -n1 -r -s -p "Press a key ... " R;
if [[ "$R" == [$S] || "$S" == "" ]]; then
printf '%s' "$R";
return 0;
else
echo;
return 1;
fi;
return 255
}
I'm not sufficiently conversant with ksh.
On 22.09.2025 03:34, Kaz Kylheku wrote:
On 2025-09-22, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
This looks very much like the function I've written for ksh
(in my various tries of all sorts of variants)... :-)
We were both trained on the same data set, so we predict
about the same tokens.
There's a chance that we're both just AIs? ;-)
f_getkey () {
stty_g=$( stty -g ) # save state
stty -echo raw
dd bs=1 count=1 2> /dev/null
stty "${stty_g}" # restore state
}
Why I don't quote the variable holding stty -g settings is that
POSIX requires it not to require quoting.
(BTW, "requires to not require" is a noteworthy formulation.)
What's the reason for that POSIX non-requirement? Because the
'stty' data isn't delimited by whitespace?
On 2025-09-22, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Why I don't quote the variable holding stty -g settings is that
POSIX requires it not to require quoting.
(BTW, "requires to not require" is a noteworthy formulation.)
What's the reason for that POSIX non-requirement?
Presumably historical practice. Existing implementations wrote a
string without whitespace or shell meta-characters, people had
been using
stty $saved
without quotes, so this was codified.
On 22/09/2025 at 01:42, Janis Papanagnou wrote:
On 21.09.2025 21:02, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote: >>>> [...]
Quick proof-of-concept bang-up:
getkey()
{
local save=$(stty -g)
stty raw -echo
local char=$(dd bs=1 count=1 2> /dev/null)
stty $save
printf "%s" "$char"
}
key=$(getkey)
This looks very much like the function I've written for ksh
(in my various tries of all sorts of variants)... :-)
f_getkey () {
stty_g=$( stty -g ) # save state
stty -echo raw
dd bs=1 count=1 2> /dev/null
stty "${stty_g}" # restore state
}
Another suggestion, to use 'read -n1', maybe in the form of
read -r -t0 -n1
might already suffice, and being a built-in it may be faster.
(The timer -t0 setting is nice for polling.)
Janis
Strikes me neither of these functions do what is described in the getkey manual page (above) which was select a keypress from a list, return 0 if
in list, 1 if not in list. My suggestion (bash):
On 21.09.2025 18:29, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Searching for 'getkey' functions [...]
OK, I found it like this.
On GitHub, I searched for the man page using a source code
search for "path:getkey.1".
Among the results, that led to this project which contains
the man page, and provides C program implementing it:
https://github.com/glensc/rc-scripts/blob/master/src/getkey.c
I have a problem with that code; it refers to a "popt.h" that leads
to a fatal error when compiling a git clone of that package. (I'm
reluctant to start invest time in projects of this type of quality.
I suppose it's easier to "re-invent" my own tool. *sigh*)
I haven't thought that there would be problems to find some standard
tool. But, OTOH, I had noticed that I already asked for such function
some time ago and also didn't find some "standard" tool. Also on the
Net (where some other folks had also asked for such tools over time)
they often got just snippy responses, and no suggestions. - It seems
to be a hard (or unworthy) request. :-)
Janis
[...]
[...]
'gcc -lpopt getkey.c -o getkey' seems to work on slackware.
On 21.09.2025 18:29, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
Searching for 'getkey' functions [...]
OK, I found it like this.
On GitHub, I searched for the man page using a source code
search for "path:getkey.1".
Among the results, that led to this project which contains
the man page, and provides C program implementing it:
https://github.com/glensc/rc-scripts/blob/master/src/getkey.c
I have a problem with that code; it refers to a "popt.h" that leads
FWIW, an attempt in C:
https://linux.die.net/man/1/getkey
getkey(1) - Linux man page
Name getkey - wait until a key is pressed
Synopsis getkey [OPTION]... [KEYS]
But that's not available on my Linux systems.
On 2025-09-22, Janis Papanagnou[rCa]
<janis_papanagnou+ng@hotmail.com> wrote:
On 21.09.2025 21:02, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou<janis_papanagnou+ng@hotmail.com> wrote:
[...]
Quick proof-of-concept bang-up:
local save=$(stty -g)
[rCa]stty $save
Why I don't quote the variable holding stty -g settings is that
POSIX requires it not to require quoting.
Kaz Kylheku <643-408-1753@kylheku.com>:
On 2025-09-22, Janis Papanagnou
<janis_papanagnou+ng@hotmail.com> wrote:
On 21.09.2025 21:02, Kaz Kylheku wrote:
On 2025-09-21, Janis Papanagnou<janis_papanagnou+ng@hotmail.com> wrote:
[...]
Quick proof-of-concept bang-up:
local save=$(stty -g)
[rCa]
stty $save
[rCa]
Why I don't quote the variable holding stty -g settings is that
POSIX requires it not to require quoting.
As far as I can see, POSIX requires
stty -g
to output one line of text consisting of only printable
characters from the portable character set, excluding white-space
characters (other than the terminating <newline>) and these
characters that could be altered by pathname expansion performed
by the shell: '*', '?', and '['.
As '(', '\', ')', '{', '|', and '}' are nonrCEwhiterCEspace
characters from the portable character set, I prefer not to do
without quoting the variable expansion:
On 2025-09-23, Helmut Waitzmann <nn.throttle@xoxy.net> wrote:
As far as I can see, POSIX requires
stty -g
to output one line of text consisting of only printable
characters from the portable character set, excluding white-space
characters (other than the terminating <newline>) and these
characters that could be altered by pathname expansion performed
by the shell: '*', '?', and '['.
That requirement is given exactly right with respect to the
intent that youc an write stty $save.
As '(', '\', ')', '{', '|', and '}' are nonrCEwhiterCEspace
characters from the portable character set, I prefer not to do
without quoting the variable expansion:
The above are syntactic tokens in the shell which are not interpreted
as such when they are the result of expansions.
The result of an unquoted parameter expansion can only undergo word splitting and pathname expansion.
Treatment of the expansion as other shell syntax requires eval.
Kaz Kylheku <643-408-1753@kylheku.com>:[...]
On 2025-09-23, Helmut Waitzmann <nn.throttle@xoxy.net> wrote:
As far as I can see, POSIX requires
stty -g
to output one line of text consisting of only printable
characters from the portable character set, excluding white-space
characters (other than the terminating <newline>) and these
characters that could be altered by pathname expansion performed
by the shell: '*', '?', and '['.
That requirement is given exactly right with respect to the
intent that you can write stty $save.
But it won't do any harm to quote anyway?