0

I have this variable in my bash script:

var="\'?"\"'\"

but when I type echo $var I get nothing. I want echo $var to return "\'?"\"'\". What should I do here?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Dudu Krem
  • 67
  • 3
  • 11
  • In addition to correct quoting when setting the variable, you should also, double-quote when you *use* the variable (e.g. `echo "$var"` instead of just `echo $var`). See ["I just assigned a variable, but `echo $variable` shows something else"](https://stackoverflow.com/questions/29378566/i-just-assigned-a-variable-but-echo-variable-shows-something-else). BTW, [shellcheck.net](https://www.shellcheck.net) is good at spotting mistakes like this. – Gordon Davisson Feb 23 '21 at 04:32
  • @DuduKrem : _I want echo $var to return "\'?"\"'\"_ ... I guess you mean .... to **output** that string, not to **return** it. In this case you have to store this string in the variable first: `var=\"\\\'\?\"\'\\\"; echo $var`. – user1934428 Feb 23 '21 at 07:04
  • did it worked ? – Jatin Mehrotra Feb 23 '21 at 09:35

1 Answers1

0

You can try this

var="'''?\"\"\""
or
var='```?"""'


echo "$var"
Jatin Mehrotra
  • 9,286
  • 4
  • 28
  • 67