dirinst comparing "X$action" with "Xdirinst" instead of $action with "dirinst"

Michael Tautschnig tautschn at model.in.tum.de
Tue Oct 3 21:25:38 CEST 2006


> Hi,
> 
> On Monday 02 October 2006 11:25, you wrote:
> >     > if [ X$action = Xdirinst ]; then
> >
> > This is normal shell coding practice. It helps if $action is not defined
> > at all. Then the test without quotes "" around an undefined variable
> > will give a syntax error.
> 
> Ah :)
> 
> But isn't 
> 
> if [ "$action" = "dirinst" ]; then
> 
> 
> the same and easier to read?
>

Actually there are reasons to use the X-thing. See, e.g.,
http://sources.redhat.com/autobook/autobook/autobook_216.html#SEC216 - quoting
it here for completeness:

"The test command does not cope with missing or additional arguments, so you must
take care to ensure that the shell does not remove arguments or introduce new
ones during variable and quote expansions. The best way to do that is to enclose
any variables in double quotes. You should also add a single character prefix to
both sides in case the value of the expansion is a valid option to test:"

However, I agree that the above is easier to read and probably expansion to
something like "-a" is not an issue here.

Cheers,
Michael
  

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://lists.uni-koeln.de/pipermail/linux-fai-devel/attachments/20061003/931715b1/attachment.bin 


More information about the linux-fai-devel mailing list