NB: Individual addresses removed, opensolaris-code preserved.
NB2: Eventually I may comment further elsewhere, as I'm not sure that
     these are the appropriate venues for a coding style thread.

+------ Roland Mainz wrote (Thu, 07-Jun-2007, 09:47 +0200):
| [EMAIL PROTECTED] wrote:
| > >
| > >    [ $install = yes ] && root="/a/" || root="/"
| > >
| > >The stuff to the right of each root= doesn't need quotes.
| > 
| > And I'm not sure about the context, but the $install would appear to need
| > some quotes.
| 
| AFAIK it depends on the content of ${install}. IMO quotes are only
| needed if the value may contain a space or any other character from
| ${IFS}, user input or a filename. If the values are guranteed to be only
| "yes" or "no" no quotes are needed ...

The other classic problem is that the variable may begin with a "-",
which test will attempt to interpret as a command line switch.  That
can be addressed either by putting the variable expansion on the right
side of the "=" or by preceeding both sides by identical strings, e.g.

        [ x$install = xyes ] && ...

which also guards against the problem of expansion of an empty variable.

My typical practice is to use "${install:-}" even when an empty variable is
handled properly, so that "set -u" can be used for testing.  I tend to use
both double quotes and curly braces more often than this shell script style
guide recommends, both for code safety and for (IMO) improved readability.
(Potential elaboration and justification deferred for now...)

Best Regards,
Chuck

_______________________________________________
opensolaris-code mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/opensolaris-code

Reply via email to