I don't understand why this doesn't work:
TEXT="blah" echo $TEXT #echoes nothingI thought it might be because echo is a builtin, so I tried this:
TEXT="blah" `which echo` $TEXT #still nothingWhat am I missing?
1 Answer
The shell expands the variables before it runs the command, even before it runs the assignments.
Cf.
text=blah ; echo $textor
text=blah eval 'echo $text'The first one works because the assignment is run as a separate command. The second one works because $text is single-quoted which prevents its expansion when shell is processing the command; when eval is later running, the variable already has the value assigned.