Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-04-2014, 05:26 PM
|
#1
|
Member
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 881
Rep: 
|
Just Curious: why do "/usr/bin/test" and "/usr/bin/[" have different sizes?
This isn't a pressing concern, but I just had a "WTF?!" moment and thought I should share the love.
Code:
dane@orchestrator ~ $ which [
/usr/bin/[
dane@orchestrator ~ $ ls -lh `which [`
-rwxr-xr-x 1 root root 35K Nov 19 2012 /usr/bin/[*
dane@orchestrator ~ $ ls -lh `which test`
-rwxr-xr-x 1 root root 31K Nov 19 2012 /usr/bin/test*
dane@orchestrator ~ $ dpkg-query -S /usr/bin/[
coreutils: /usr/bin/[
dane@orchestrator ~ $ dpkg-query -S /usr/bin/test
coreutils: /usr/bin/test
So...how does this work?
(Have fun!)
--Dane
|
|
|
01-04-2014, 05:53 PM
|
#2
|
Moderator
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,324
|
Because they are not the identical.
That sounds like a tautology, but it is not.
Among their differences are their usage syntax and the fact that [ honors --help and --version options while test does not.
So while we speak and think of them as being the same thing, they really are not (at least the GNU versions).
Last edited by astrogeek; 01-04-2014 at 05:58 PM.
|
|
1 members found this post helpful.
|
01-05-2014, 07:20 AM
|
#3
|
Member
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 881
Original Poster
Rep: 
|
Are there functional differences, other than --help and --version?
|
|
|
01-05-2014, 07:46 AM
|
#4
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
A heads up about test, test and [ (yep, test is mentioned twice).
There is also a bash internal command called test, which is actually used when not using the full path to the test binary (/usr/bin/test). See man bash, the SHELL BUILTIN COMMANDS section.
The binary [ and binary test work the same way (except for the --version/--help), as you might have noticed both point to the saem manual page.
The binary and the build in do have some differences (availability and names of options).
|
|
3 members found this post helpful.
|
01-06-2014, 12:54 AM
|
#5
|
Member
Registered: Oct 2003
Location: Chico, CA, USA
Distribution: Linux Mint
Posts: 881
Original Poster
Rep: 
|
Ah, excellent distinction! Thanks, druuna.
|
|
|
01-06-2014, 03:33 AM
|
#6
|
Member
Registered: Aug 2008
Distribution: Debian
Posts: 523
|
Take a look at source code of test and [ for yourself. The only difference starts at line 837.
The reason test does not recognise any options is that it would not be possible to distinguish whether the option was actual option or a test. I.e. “test "$FOO"” is a valid way to test whether the variable FOO is empty or not, however if FOO was “--help” or “--version”, the test would result in superfluous output.
[ can support options since its valid invocation requires “]” at the end of the command.
Quote:
Originally Posted by druuna
There is also a bash internal command called test, which is actually used when not using the full path to the test binary (/usr/bin/test). See man bash, the SHELL BUILTIN COMMANDS section.
|
There is also a bash built-in “[” (which does not support “--help” or “--version” by the way).
PS. This of course does not change the fact that both binaries could be the same and the behaviour could be changed based on “argv[0]”. I assume this is not the cases to speed things up slightly.
Last edited by mina86; 01-06-2014 at 03:36 AM.
|
|
1 members found this post helpful.
|
All times are GMT -5. The time now is 04:12 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|