bug-bash
[Top][All Lists]
Advanced

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

Re: read and env variables + POSIX => SEGFAULT


From: Linda Walsh
Subject: Re: read and env variables + POSIX => SEGFAULT
Date: Mon, 12 Oct 2015 16:39:45 -0700
User-agent: Thunderbird



(Cc: Chet Ramey... forgot to send it to list...oop)


Chet Ramey wrote:
On 10/10/15 11:01 PM, Linda Walsh wrote:

a= read a <<< x;echo $?
0
declare -p a
declare -- a="x"
#  the manpage claims "one line is read from [the input], and the result
#  is split by words and assigns 1st word to 1st var and so forth, but
# apparently the reading of 1 line is optional -- though this is consistent
#  with the fact that read can be told to read some number of characters
and #  return when the limit is reached.  So technically, read doesn't
"read one line",
#  but read whatever is on 'input' up to 1 line.  (DOC clarification?)

This is terribly wrong.

The command in question is `a= read a <<< x'.

The here-string construct takes the following word and, like a here
document, makes it the standard input to the command.  The standard
input is then a file consisting of a single line: x\n.

It's basically shorthand for

read a <<EOF
x
EOF

So, `read' reads the single line from its standard input and assigns it
to the variable `a'.
----
I wasn't sure if it put the "\n" at the end in a 1-line example.

Does it also use a tmp file and use process-substitution, or is
that only when parens are present?  I.e.

read a < <( echo x)

I'm under the impression, uses a tmp file.

does the read a <<< x
also use a tmp file?

I.e. is
readarray -t a < <( echo -e 'x\ny\n')
declare -p a
declare -a a='([0]="x" [1]="y")'

implemented the same way as
a=(x y)
b=$(printf "%s\n" ${a[@]})
readarray -t ar <<< "${b[@]}"
declare -p a
declare -a a='([0]="x" [1]="y")'










reply via email to

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