Skip to main content
2 of 3
added 241 characters in body
cuonglm
  • 158.1k
  • 41
  • 341
  • 420

You have mistaken, double quotes "$b" does not prevent parameter expansion, it prevents pathname expansion (aka globbing) and fields splitting.

If you want to prevent parameter expansion, you need to use quoting, like single quote '$b' or escaping \$b:

$ echo '$b'

or:

$ echo \$b

then $b is output literal.


In the example, there's nothing prevent parameter expansion.

When the shell read the input c=$(b=2; echo $b), it perform token recognition, saw that $( is token for command substitution. So it treats the rest of string between $( and ) to be interpreted in subshell created by command substitution, not the current shell.

cuonglm
  • 158.1k
  • 41
  • 341
  • 420