Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
In this case, $? always returs a number which signifies exit status of previous command(s). So quoting or not quoting is irrelevant for this one, but quoting exists to avoid word splitting, aka treating items separately. With variable v='hello world' , when you use bare $v shell will treat its expansion as two elements hello and world, with quotes - "$v" is treated as single unit. Read the linked posts, it's explained much more in-depth there.
$?
always returs a number which signifies exit status of previous command(s). So quoting or not quoting is irrelevant for this one, but quoting exists to avoid word splitting, aka treating items separately. With variablev='hello world'
, when you use bare$v
shell will treat its expansion as two elementshello
andworld
, with quotes -"$v"
is treated as single unit. Read the linked posts, it's explained much more in-depth there.v='1234 5678'