3

I want to simply wait for the user to acknowledge a message by pressing Return. In bash, I am able to call

$ read

$ 

However, in sh (dash in my case), I get

$ read
sh: 1: read: arg count
$ 

It seems like I must provide an argument? Where does that difference come from?

  • I'd start by typing type read plus Return ... and if the output says something about a built-in you probably have the explanation right there. Other possible outputs would be the path to some binary, a function of the name or an alias of the name (hope I didn't forget one). According to the dash man page you have shell functions, builtin commands, and normal programs there. The builtin command would allow you to refer to the command (e.g. /bin/read) ... simply say command read. – 0xC0000022L Apr 20 '20 at 21:08
8

The standard read utility takes at least one variable's name.

Some shell's read implementation uses a default variable, like REPLY, to store the read data if no name is supplied, but dash, aiming to be a POSIX compliant shell, does not (as it's not required to do so by the standard). The equivalent in the dash shell would be

read REPLY

The bash shell, even in its POSIX mode, does keep some non-POSIX features enabled. This is one of them, which means that read with no variable's name will work even if you run a bash --posix shell.

For a full list of things that happens when you enable POSIX mode in bash (which this question really isn't about), see https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html

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.