Why do I get
/tmp/test: line 4: 0=Done: command not found
from the below
a="0"
while [ true ]; do
$a="Done"
exit
done
echo $a
I were expecting it would output Done.
You don't need to use the $ when defining a variable, only when you are accessing it.
You'll need to change the line defining the variable a to:
a="Done"
As to an explanation, what I believe is happening here is that $a is being resolved to 0 and then the shell is seeing the entire 0=Done as a single (unfound) command. Accessing undefined variables still returns a 0 exit code.
breakto exit a loop.exitwill exit the whole shell.while [ true ]loop at all if you have an unconditionalbreakorexit?true" when you could just execute thetruecommand (i.e.while true; do ...; done). Not that there's any point in a loop with unconditionalbreak, but...