0
var='one "second stuff" third'
array=($var) 

Should return an array of [0] one [1] second stuff [2] third but instead returns an array of 4 items splitting "second stuff" in 2 even though that item is double quoted. Why?

programmer
  • 41
  • 6
  • 1
    The shell parses quotes before expanding variables, so quotes in the values of variables don't do anything useful; by the time there're part of the command, it's too late. See ["Why does shell ignore quoting characters in arguments passed to it through variables?"](https://stackoverflow.com/questions/12136948) (but don't use `eval` -- that way lies madness), ["Reading quoted/escaped arguments correctly from a string"](https://stackoverflow.com/questions/26067249), and ["Get bash to respect quotes when word splitting subshell output"](https://superuser.com/questions/1529226). – Gordon Davisson Oct 18 '21 at 02:47
  • 1
    Try to define an array like this.```array=("one" "second stuff" "third")``` – 过过招 Oct 18 '21 at 02:50

0 Answers0