0

In Bash, when I run echo 'hello', this will output hello, whereas if I put the same command in a variable (i.e., HELLO="echo 'hello'") and run from the variable instead (i.e., $HELLO) the output is 'hello' (note single quotes).

Instead if I run eval $HELLO the output is the same as running echo 'hello' (i.e., the output is hello, without single quotes).

I am trying to understand why running a command from a variable (i.e., $HELLO) behaves differently in Bash.

Thank you.

Ali
  • 1,396
  • 14
  • 37
  • https://mywiki.wooledge.org/BashFAQ/050 – Biffen Oct 30 '20 at 11:29
  • It's because variables get expanded partway through the process of parsing a command; because of this, the value of the variable is only *partly* parsed (it misses the earlier phases of parsing... like quote processing). – Gordon Davisson Oct 30 '20 at 12:59

0 Answers0