• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

echo hello | read name #no work

Doyan

n00b
Joined
Nov 9, 2006
Messages
18
Hi, I am stumped as to why the follow command does not work.

Code:
echo hello | read name

I have tried the command on a couple different linux distro's and it does not save the word hello in the name variable. Odd thing is it doesn't return a error either, it returns the prompt which leads me to believe it worked but when I echo the variable $name, nothing is saved in it.
 
The problem is that when you use a pipe the read command is being executed in a subshell, so you can't access the variable locally. As to how to get around that...my shell scripting skills are rather lacking. >.>
 
Since people have been posting "better" ways todo this (and they are right) I thought I would just post how todo what you want (if you /really/ want todo it that way...)

read, reads from stdin, thus you must pass it data from stdin. a PIPE is NOT!!! stdin

Code:
read name < <(echo hello)
echo $name
 
Back
Top