0

As picture shows, why bash insert such weird token '\' into my script when I use single quotes inside double quotes? enter image description here

code sample:

set +vx

cmd="echo 'hello this is a test'"

Stan
  • 602
  • 6
  • 23
  • 1
    Storing commands in variables doesn't work; see ["How to execute a bash command stored as a string with quotes and asterisk"](https://stackoverflow.com/questions/2005192) and [BashFAQ #50: "I'm trying to put a command in a variable, but the complex cases always fail!"](http://mywiki.wooledge.org/BashFAQ/050). – Gordon Davisson Mar 20 '22 at 03:09
  • 1
    Since the single-quotes are coming from a variable, they're treated as data rather than syntactic quotes, and in the `set -x` output they're escaped to indicate this. See the Unix&Linux question ["Why does bash add single quotes to unquoted failed pathname expansions in a command before executing it?"](https://unix.stackexchange.com/questions/118403). – Gordon Davisson Mar 20 '22 at 03:13

0 Answers0