help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash read error


From: Greg Wooledge
Subject: Re: bash read error
Date: Wed, 1 Jun 2022 07:52:03 -0400

On Wed, Jun 01, 2022 at 12:47:32PM +0200, Pascal wrote:
> it's OK if I try this :
> 
> wpa_supplicant -B -i wlan1 -c <(
> cat <<~~~~
> network={
> ...
> identity="test"
> password=hash:0cb6948805f797bf2a82807973b89537
> }
> ~~~~
> )

So... the -c option of wpa_supplicant expects a filename?  OK.

> but it's KO with bash: read: read error: 0: Input/output errors if I try to
> read and convert informations before "cating" configuration :
> 
> wpa_supplicant -B -i wlan1 -c <(
> read -p 'user     ? ' user
> read -p 'password ? ' -s passwd
> cat <<~~~~
> network={
> ...
> identity="${user}"
> password=hash:$( echo -n "${passwd}" | iconv -t utf16le | openssl md4 |
> egrep -o '.{32}$' )
> }
> ~~~~
> )
> user     ? bash: read: read error: 0: Input/output error
> password ? bash: read: read error: 0: Input/output error

Where is that 'read' supposed to be reading from?  The terminal?
It's running as a background process, because it's inside a <() process
substitution.  Background processes can't read from a terminal.

> on the other hand, the use of a pipe is not a problem :
> 
> (
> read -p 'user     ? ' user
> read -p 'password ? ' -s passwd
> cat <<~~~~

In this case, the 'read' commands are running in a foreground process.
So they *can* read from a terminal.

If you want the 'read' commands to work, and to use their values in
a background process substitution, I would simply separate the two.
Don't try to do them all in the same spot.

read -r -p 'user: ' user
read -r -s -p 'password: ' password
wpa_supplicant .... -c <( stuff using $user and $password )



reply via email to

[Prev in Thread] Current Thread [Next in Thread]