Skip to main content
Fixed up the grammar.
Source Link
Alexis Wilke
  • 3.1k
  • 2
  • 29
  • 49

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 literalliterally.


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

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

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.

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 literally.


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

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

added 241 characters in body
Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

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:

$ b=1echo '$b'

or:

$ echo '$b'\$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.

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 single quote '$b':

$ b=1
$ 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.

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.

Source Link
cuonglm
  • 158.1k
  • 41
  • 341
  • 419

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 single quote '$b':

$ b=1
$ 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.