Linked Questions
29 questions linked to/from In bash, read after a pipe is not setting values
6
votes
3
answers
4k
views
Why must I put the command read into a subshell while using pipeline [duplicate]
The command df . can show us which device we are on. For example,
me@ubuntu1804:~$ df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sdb1 61664044 8510340 49991644 15% /home
...
4
votes
2
answers
10k
views
Append to global variable inside a loop? [duplicate]
I have a global variable $EMAIL. I want to loop through several files and for each that meets a criteria I will add it to $EMAIL for report generation.
The problem is when I redefine $EMAIL inside ...
2
votes
1
answer
7k
views
read from stdin works differently in bash and zsh [duplicate]
I'm trying to pipe a command's output to the read builtin of my shell and I get a different behaviour for zsh and bash:
$ bash -c 'echo hello | read test; echo $test'
$ zsh -c 'echo hello | read ...
0
votes
1
answer
11k
views
Export environment variables parsed from YAML text file [duplicate]
I have some environment variables declared in a YAML file like:
runtime: python37
env_variables:
API_URL: 'https://fake.api.com/'
API_USERNAME: '[email protected]'
API_PASSWORD: 'Passwooord'
I ...
4
votes
1
answer
3k
views
How can I make `read` read from stdin? [duplicate]
bash builtin command read is said to accept input from stdin, but why does the following not read in anything?
$ printf "%s" "a b" | read line
$ printf "%s" "$line"
$
Thanks.
1
vote
1
answer
1k
views
pipe for read command does not work [duplicate]
read command in sh works if I redirect file1 as standard input like
$ cat file1
first second
$ read u v <file1
$ echo $u
first
$ echo $v
second
However, if I redirect standard output from echo ...
1
vote
1
answer
815
views
Why doesn't read command work with echo and piping? [duplicate]
With regard to the below commands:
$ unset a
$ echo 12 | read a
$ echo $a
$
I was expecting that a would be set the value of 12 in the second statement. But it turns out that a is still unset.
0
votes
1
answer
367
views
bash: IFS not honoured by read command [duplicate]
From the bash man page for the read command:
One line is read from the standard input, or from the file descriptor fd supplied as an argument to the -u option, split into words as described above ...
0
votes
0
answers
1k
views
Understanding bash read variable substitution [duplicate]
First of all, I have little experience using Bash and I apologize for my bad English.
Maybe it's obvious.
I am trying to understand why Bash drop value of the variable in this oneliner.
echo "...
-1
votes
1
answer
232
views
In Bash why echo hello | read myvar && echo $myvar doesn't output? Zsh works fine [duplicate]
I quite don't understand why Bash would not hold the value of myvar in this example.
echo hello | read myvar && echo $myvar
I would understand if I were running that command as two separate ...
0
votes
0
answers
236
views
Unexpected behavior during index assignment in a Bash array [duplicate]
I'm having trouble assigning values to a specific bash index,
but apparently only when the index variable is set using a while read loop.
Taking this code as a test example:
#!/bin/bash
read -d '' ...
1
vote
1
answer
73
views
variable doesn't change after find & while [duplicate]
My code
var=34
find $1 -type f | while read line;
do
file_status=`file "$line"`
file_name=`echo $line | sed s/".*\/"//g`
line_length=${#file_name}
if [ $line_length -...
1
vote
0
answers
34
views
Variable not available outside function [duplicate]
I'm having difficulties understanding the following example I created.
The variable glob_var gets changed inside the test() function, but the original value remains outside of the function:
test() {
...
0
votes
0
answers
37
views
piping echo into read with and without while loop [duplicate]
why does a echo | read behave differently to echo | while read?
$ echo -e "1\t2\t3" | read a b c; echo "$a-$b-$c"
--
$ echo -e "1\t2\t3" | while read a b c; do echo &...
1
vote
0
answers
22
views
What is different between piping and here-strings for the `read` builtin? [duplicate]
I thought that piping from echo was equivalent to here strings, but the REPLY variable of the read builtin command is only set (or in scope I guess) when using here strings:
echo foo | read;echo $...