When to wrap quotes around a shell variable?
问题 Could someone tell me whether or not I should wrap quotes around variables in a shell script? For example, is the following correct: xdg-open $URL [ $? -eq 2 ] or xdg-open \"$URL\" [ \"$?\" -eq \"2\" ] And if so, why? 回答1: General rule: quote it if it can either be empty or contain spaces (or any whitespace really) or special characters (wildcards). Not quoting strings with spaces often leads to the shell breaking apart a single argument into many. $? doesn't need quotes since it's a numeric