1

Is there any reason for doing something like:

a="abc"

or

a='abc'

The quotes seem completely superfluous, but then there might be some hideous corner case... I'm interested in Bash and Sh in particular, but answer about the other ones as well if you can and will.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
  • Linking in for related questions: https://unix.stackexchange.com/questions/400447/whats-a-good-mnemonic-for-shell-double-vs-single-quotes and https://unix.stackexchange.com/questions/97560/are-quotes-needed-for-local-variable-assignment – Jeff Schaller Jun 17 '18 at 01:17
  • 1
    The only reason I quote the right hand side of an assignment like that (static string) is if anyone later decides that they'd want a space in the string (e.g. it's a long pathname that someone might modify, not realizing it's unquoted). – Kusalananda Jun 17 '18 at 06:49
  • 1
    Sure, you could drop the quotes for simple cases like that, but I don't advise it. You want to train your brain so that quoting becomes second nature. That way, you're much less likely to forget to quote when it's critical to do so, and you'll find it easier to debug, since stuff with missing quotes will look obviously wrong. – PM 2Ring Jun 17 '18 at 10:17

0 Answers0