On Wed, 30 Sep 2020 17:55:12 +0100, RobH wrote:
> On 30/09/2020 16:14, Martin Gregorie wrote:
>> read -n1 -s
>
> Running the read -nl -s in a terminal, just hangs, as it waiting for
> some other command maybe
NO! as I said, its asking for you to press any key. Read its manpage
$ man read
shows you the bash manual search down for the 'read' builtin command.
This will tell you that:
- 'read' defaults to reading from stdin, which is connected to the
terminal when you run it from the terminal)
- that the -n option says how many characters it should read
(so -n1 will read one character)
- that the -s option tells it not to echo its input
In other words, you saw 'read' doing exactly what you asked: to wait for
one keystroke and silently exit when you hit a key.
Try running this script:
===========demo script starts on the next line ===================
#! /bin/bash
#
echo "Hit any key to continue"
read -n1 -s
echo "Continuing..."
===========demo script ends on the previous line ===================
save these 5 lines as a file called 'demo',
make it executable ('chmod u+x demo')
and run it. Now it may be clearer that 'read' is not your problem.
You should also get used to using the 'man' and 'apropos' commands.
'man' describes how to use every command (and every function in the C
standard library....) and 'apropos' searches for commands, functions, etc
that match your search term, so the command 'apropos file' lists all the
commands that work with files.
--
Martin | martin at
Gregorie | gregorie dot org
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|