On 22Apr2016 15:04, Jon LaBadie <mut...@jgcomp.com> wrote:
On Fri, Apr 22, 2016 at 12:34:48AM -0700, David Champion wrote:
* On 21 Apr 2016, Jon LaBadie wrote:
> Unless it has changed recently, bash runs redirected read
> commands in a sub-process.  Thus the variable fn would not
> get set in the main process.

I haven't run into this (that I recall) with regular input redirection.
It does happen with piped input redirection (to a read) because the
pipeline terminal isn't the current shell.

yes:
read fn </dev/tty

no:
cat /dev/tty | read fn

Thanks for the correction David.
My negative bash experience was with pipes as in:

 date | read wday mon day time zone yr

which works fine in ksh and zsh.  I badly assumed
the limitation was to any redirection.

Yah, the active thing is not the readirect, it is that a pipeline needs to put at least all but one command as separate processes, and most shells will make all the commands separate processes (including the final "read" from your example).

I usually do this:

 date \
 | { read wday mon day time zone yr
     ... use $wday etc here - in the same shell as the "read" ...
   }

Cheers,
Cameron Simpson <c...@zip.com.au>

Reply via email to