I want to execute echo and get an output like:
$ export EVAR="-E"
$ echo "$EVAR"
-E
I have stored "-E" in a bash variable, say $EVAR
. If I execute echo $EVAR
, echo will print out nothing. Perhaps it thinks $EVAR is an argument -E. Quoting $EVAR
inside double quote marks doesn't work either.
How can I print it out?
NOTE: I imagine there could be a solution which is ignorant on the content of $EVAR
- with no analysis on the content of $EVAR, a command like echo some-arg $EVAR
. Is that possible? Or should I only turn to a workround like printf
?
printf "%s\n" "$EVAR"
... – jasonwryan Dec 18 '15 at 02:47$EVAR
? – clarity123 Dec 18 '15 at 04:13printf
isn't a workaround; it's the only method of printing variables you should be using, period. Skipecho
. See "Why is printf better than echo" as linked above. – Wildcard Dec 18 '15 at 07:33