FS#21759 - [filesystem] /etc/profile, test -a

Attached to Project: Arch Linux
Opened by Taylan Ulrich B. (taylanub) - Saturday, 20 November 2010, 12:45 GMT
Last edited by Pierre Schmitz (Pierre) - Monday, 22 November 2010, 18:30 GMT
Task Type Bug Report
Category Packages: Testing
Status Closed
Assigned To Pierre Schmitz (Pierre)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Using '-a' in 'test ...' aka '[ ... ]' is discouraged; behaviour is not fully standardized.
Using multiple tests with && and || is always safe.
This task depends upon

Closed by  Pierre Schmitz (Pierre)
Monday, 22 November 2010, 18:30 GMT
Reason for closing:  Fixed
Comment by Pierre Schmitz (Pierre) - Saturday, 20 November 2010, 12:56 GMT
Ah, forgot that the shell might call its built-in test when not called with full path. What about explicitly using /usr/bin/test? That should always work and we already depend on coreutils anyway.
Comment by (Lavandero) - Sunday, 21 November 2010, 02:57 GMT
Shells that have a problem with [ ] also have a problem with $(), which is present in /etc/profile.

Why not just require POSIX conformance as a minimum? That way [] and $() can be used.
Comment by Taylan Ulrich B. (taylanub) - Sunday, 21 November 2010, 05:58 GMT
If you'd read test(1p), i.e. the POSIX manpage for test reachable with "man 1p test", you'd see that it even says results are unspecified if there is merely more than 4 arguments.
There is a section about "XSI-conformant" systems, talking about more complex rules defining the behaviour of -a and -o, and those might just work, but there is simply no objective advantage of those over using the _simple_ and safe-to-work && and ||.
Remember that 'test' is usually builtin and calling it many times won't cause slow-down. Even if /usr/bin/test would be called a bunch of times, it would probably be a nanosecond difference anyway.

Using /usr/bin/test explicitly doesn't make sense in my opinion. POSIX conformance as a minimum must obviously be, again in my opinion. Also, using && and || will of course work with /usr/bin/test too, so once again, it's just fail-proof.
Comment by Pierre Schmitz (Pierre) - Monday, 22 November 2010, 18:30 GMT
Even though I haven't found a shell having a problem with this in our repos it is probably more safe to use && here. Thanks for looking into this.

Loading...