[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read unexpected reads directory list
From: |
Greg Wooledge |
Subject: |
Re: read unexpected reads directory list |
Date: |
Tue, 31 Mar 2015 12:06:20 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Tue, Mar 31, 2015 at 06:04:53PM +0300, Filimonov Vadim wrote:
> filimonov@filimonov:~/bashbug/bash-4.3$ read -u63 LINE <(echo "*")
> bash: read: `/dev/fd/63': not a valid identifier
You are missing a < sign here. You probably wanted:
read LINE < <(echo "*")
It is not safe to assume that the <() will produce a reference to file
descriptor 63. On many platforms, it won't even use /dev/fd/ at all,
but will instead use a named pipe.
Your command expands to
read -u63 LINE /dev/fd/63
Which produces the error message, as it tries to treat /dev/fd/63 as
a variable name to assign into. However, before it runs into that
error, it has already read a "*" character from file descriptor 63
(since you told it to do that with -u63). And that * character is now
in the variable named LINE.
> ... ;echo $LINE
> ABOUT-NLS aclocal.m4 alias.c alias.h alias.o array.c arrayfunc.c arrayfunc.h
> arrayfunc.o array.h array.o assoc.c assoc.h assoc.o AUTHORS bash bashansi.h
> bashbug bashhist.c bashhist.h bashhist.o bashintl.h bashjmp
You always want echo "$LINE" and *never* echo $LINE.
http://mywiki.wooledge.org/BashPitfalls#pf14
The * from $LINE was expanded because you failed to quote properly.