[b]My thoughts (and current practise) when it comes to braces and quoting.[/b]

[u]Braces[/u]

I have always used braces around all my variable references, except for 
positional parameters. I do it for consistency. No need to remember that in 
some situations I can skip the braces, while in others I need to have them in.

[b]Quoting[/b]

I also use quoting a lot, even when it is not strictly necessary. E.g. in 
variable assignments when it is a text value, but not when it is a numeric 
value:

filename="/path/to/file"
errcode=1

if [ -r "${filename}" ]; then
.... print "Sorry - '${filename}' does not exist."
....exit "${errcode}"
fi

I might know that a variable contains a safe value, is always non-empty, etc, 
but coding mistakes happens, so why take the chance?

Since I use an editor (Vim) that do syntax highlighting, quoting all my strings 
also helps the string values stand out, and the editor will help me spot when I 
forget to terminate quoted string.
 
 
This message posted from opensolaris.org
_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to