Why does every example I see have while IFS= read line and not while IFS=; read line?
I thought that name=value command might set a local variable but sentence="hello" echo $sentencedoesn’t work, while sentence="hello"; echo $sentence does.
The:
syntax sets the
nametovaluefor thecommand. In your example:the $sentence is expanded by the calling shell, which does not see the setting. If you do
(note the single quotes to have the
$expanded by the called shell) it will echohello. And if you tryit will not echo anything, because
sentenceis set in the current shell, but not in the called one, since it was not exported. Sowill not work, because
readwill not see theIFSsetting.