* [gentoo-user] strange [ file @ 2006-07-25 9:00 Arnau Bria 2006-07-25 9:06 ` Dale ` (5 more replies) 0 siblings, 6 replies; 27+ messages in thread From: Arnau Bria @ 2006-07-25 9:00 UTC (permalink / raw To: gentoo-user Hi, I've seen a file named "[" in my /usr/bin ... #file "[" [: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.4.1, dynamically linked (uses shared libs), for GNU/Linux 2.4.1, stripped in I can find things like: [...] -ot does not accept -l %s: unary operator expected %s: binary operator expected ')' expected, found %s ')' expected test and/or [ Report bugs to <%s>. bug-coreutils at gnu.org/usr/share/localeMatthew BradburnKevin Braunsdorf5.94GNU coreutilsmissing `]' Try `%s --help' for more information. Usage: test EXPRESSION or: test or: [ EXPRESSION ] or: [ ] or: [ OPTION Exit with the status determined by EXPRESSION. [...] does any one know what could it be?¿ thanks in advance. -- Arnau Bria http://blog.emergetux.net La vida es una aplastante derrota tras otra hasta que acabas deseando que se muera Flanders. ~Homer J. Simpson~ -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:00 [gentoo-user] strange [ file Arnau Bria @ 2006-07-25 9:06 ` Dale 2006-07-25 9:13 ` Christoph Eckert ` (4 subsequent siblings) 5 siblings, 0 replies; 27+ messages in thread From: Dale @ 2006-07-25 9:06 UTC (permalink / raw To: gentoo-user Arnau Bria wrote: > Hi, > > I've seen a file named "[" in my /usr/bin ... > > #file "[" > [: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for > GNU/Linux 2.4.1, dynamically linked (uses shared libs), for GNU/Linux > 2.4.1, stripped > > in I can find things like: > [...] > -ot does not accept -l > %s: unary operator expected > %s: binary operator expected > ')' expected, found %s > ')' expected > test and/or [ > Report bugs to <%s>. > bug-coreutils at gnu.org/usr/share/localeMatthew BradburnKevin > Braunsdorf5.94GNU coreutilsmissing `]' Try `%s --help' for more > information. Usage: test EXPRESSION > or: test > or: [ EXPRESSION ] > or: [ ] > or: [ OPTION > Exit with the status determined by EXPRESSION. > [...] > > does any one know what could it be?¿ > thanks in advance. > This may help a little: > root@smoker / # equery belongs [ > [ Searching for file(s) [ in *... ] > sys-apps/coreutils-5.94-r1 (/usr/bin/[) > root@smoker / # It's part of coreutils. At least someone isn't putting something on your system you don't know about. It is weird that they named it that though. Dale :-) :-) -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:00 [gentoo-user] strange [ file Arnau Bria 2006-07-25 9:06 ` Dale @ 2006-07-25 9:13 ` Christoph Eckert 2006-07-25 9:14 ` Richard Fish ` (3 subsequent siblings) 5 siblings, 0 replies; 27+ messages in thread From: Christoph Eckert @ 2006-07-25 9:13 UTC (permalink / raw To: gentoo-user > does any one know what could it be?¿ AFAIK it's a synonym to »test«. Best regards ce -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:00 [gentoo-user] strange [ file Arnau Bria 2006-07-25 9:06 ` Dale 2006-07-25 9:13 ` Christoph Eckert @ 2006-07-25 9:14 ` Richard Fish 2006-07-25 9:36 ` Arnau Bria 2006-07-25 11:00 ` Alexander Skwar 2006-07-25 9:17 ` Dirk Heinrichs ` (2 subsequent siblings) 5 siblings, 2 replies; 27+ messages in thread From: Richard Fish @ 2006-07-25 9:14 UTC (permalink / raw To: gentoo-user On 7/25/06, Arnau Bria <arnau@emergetux.net> wrote: > Hi, > > I've seen a file named "[" in my /usr/bin ... Perfectly normal. It is a program that implements bash style tests for script environments that don't normally do them. For example: if [ -f /etc/passwd ] ; then echo "/etc/passwd exists and is a regular file" fi Notice the "[" after the "if".... "man test" will give you the user manual for it. More generally, merge gentoolkit, and you can use equery to find out where things come from. Ex: ~ > equery belongs "/usr/bin/[" [ Searching for file(s) /usr/bin/[ in *... ] sys-apps/coreutils-5.97 (/usr/bin/[) ~ > equery check coreutils [ Checking sys-apps/coreutils-5.97 ] * 318 out of 318 files good -Richard -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:14 ` Richard Fish @ 2006-07-25 9:36 ` Arnau Bria 2006-07-25 9:55 ` Neil Bothwick 2006-07-25 11:00 ` Alexander Skwar 1 sibling, 1 reply; 27+ messages in thread From: Arnau Bria @ 2006-07-25 9:36 UTC (permalink / raw To: gentoo-user On Tue, 25 Jul 2006 02:14:02 -0700 Richard Fish wrote: > On 7/25/06, Arnau Bria <arnau@emergetux.net> wrote: > > Hi, > > > > I've seen a file named "[" in my /usr/bin ... > > Perfectly normal. It is a program that implements bash style tests > for script environments that don't normally do them. For example: > > if [ -f /etc/passwd ] ; then > echo "/etc/passwd exists and is a regular file" > fi > > Notice the "[" after the "if".... > > "man test" will give you the user manual for it. Thanks, I'll take a look right now. > More generally, merge gentoolkit, and you can use equery to find out > where things come from. Ex: > ~ > equery belongs "/usr/bin/[" [...] sure, but I supposed that if it was a strange file, it could come from a corrupt source from coreutils. (I already looked for it with equery, but its strange name make me confused). I have a periodically rkhunter runnig in my system, but I was afraid I got a corrupted source package... > -Richard even though answering only to Richard, thanks to all who answered my question! Cheers! -- Arnau Bria http://blog.emergetux.net La vida es una aplastante derrota tras otra hasta que acabas deseando que se muera Flanders. ~Homer J. Simpson~ -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:36 ` Arnau Bria @ 2006-07-25 9:55 ` Neil Bothwick 0 siblings, 0 replies; 27+ messages in thread From: Neil Bothwick @ 2006-07-25 9:55 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 413 bytes --] On Tue, 25 Jul 2006 11:36:55 +0200, Arnau Bria wrote: > I have a periodically rkhunter runnig in my system, but I was afraid I > got a corrupted source package... Portage would refuse to install from a corrupted source package, because it verifies the checksums of all files it uses. -- Neil Bothwick "Bother!." said Pooh, trying to uninstall freeserve from his PeeCee for the umpteenth time. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:14 ` Richard Fish 2006-07-25 9:36 ` Arnau Bria @ 2006-07-25 11:00 ` Alexander Skwar 1 sibling, 0 replies; 27+ messages in thread From: Alexander Skwar @ 2006-07-25 11:00 UTC (permalink / raw To: gentoo-user Richard Fish wrote: > On 7/25/06, Arnau Bria <arnau@emergetux.net> wrote: >> Hi, >> >> I've seen a file named "[" in my /usr/bin ... > > Perfectly normal. It is a program that implements bash style tests Not *bash* style tests. bash doesn't have much to do with this. > for script environments that don't normally do them. For example: > > if [ -f /etc/passwd ] ; then > echo "/etc/passwd exists and is a regular file" > fi > > Notice the "[" after the "if".... However, [ is normally a shell builtin and thus /usr/bin/[ isn't executed. Alexander Skwar -- Give a man a fish, and you feed him for a day. Teach a man to fish, and he'll invite himself over for dinner. - Calvin Keegan -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:00 [gentoo-user] strange [ file Arnau Bria ` (2 preceding siblings ...) 2006-07-25 9:14 ` Richard Fish @ 2006-07-25 9:17 ` Dirk Heinrichs 2006-07-25 11:02 ` Alexander Skwar 2006-07-25 9:20 ` Neil Bothwick 2006-07-25 9:34 ` [gentoo-user] " Marco Costa 5 siblings, 1 reply; 27+ messages in thread From: Dirk Heinrichs @ 2006-07-25 9:17 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 593 bytes --] Am Dienstag, 25. Juli 2006 11:00 schrieb ext Arnau Bria: > I've seen a file named "[" in my /usr/bin ... > [...] > > does any one know what could it be?¿ It's the [ from "if [ condition ]; then ...", a shortcut for /usr/bin/test. HTH... Dirk -- Dirk Heinrichs | Tel: +49 (0)162 234 3408 Configuration Manager | Fax: +49 (0)211 47068 111 Capgemini Deutschland | Mail: dirk.heinrichs@capgemini.com Hambornerstraße 55 | Web: http://www.capgemini.com D-40472 Düsseldorf | ICQ#: 110037733 GPG Public Key C2E467BB | Keyserver: www.keyserver.net [-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:17 ` Dirk Heinrichs @ 2006-07-25 11:02 ` Alexander Skwar 2006-07-25 12:11 ` Dirk Heinrichs 2006-07-25 12:26 ` Hagen Soengen 0 siblings, 2 replies; 27+ messages in thread From: Alexander Skwar @ 2006-07-25 11:02 UTC (permalink / raw To: gentoo-user Dirk Heinrichs wrote: > Am Dienstag, 25. Juli 2006 11:00 schrieb ext Arnau Bria: > >> I've seen a file named "[" in my /usr/bin ... >> [...] >> >> does any one know what could it be?¿ > > It's the [ from "if [ condition ]; then ...", a shortcut for /usr/bin/test. Nope, not correct. [09:39:58 vz6tml@dewup-ww02:~] $ type [ [ is a shell builtin [13:01:25 vz6tml@dewup-ww02:~] $ type test test is a shell builtin And actually /usr/bin/[ and /usr/bin/test aren't even the same: [13:01:56 vz6tml@dewup-ww02:~] $ ls -la /usr/bin/{[,test} -rwxr-xr-x 1 root root 24852 27. Jun 09:34 /usr/bin/[ -rwxr-xr-x 1 root root 22784 27. Jun 09:34 /usr/bin/test I wonder where the differences are. I would've expected that test and [ were hardlinks. Alexander Skwar -- Is it 1974? What's for SUPPER? Can I spend my COLLEGE FUND in one wild afternoon?? -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 11:02 ` Alexander Skwar @ 2006-07-25 12:11 ` Dirk Heinrichs 2006-07-25 12:26 ` Hagen Soengen 1 sibling, 0 replies; 27+ messages in thread From: Dirk Heinrichs @ 2006-07-25 12:11 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 775 bytes --] Am Dienstag, 25. Juli 2006 13:02 schrieb ext Alexander Skwar: > Dirk Heinrichs wrote: > > Am Dienstag, 25. Juli 2006 11:00 schrieb ext Arnau Bria: > >> I've seen a file named "[" in my /usr/bin ... > >> [...] > >> > >> does any one know what could it be?¿ > > > > It's the [ from "if [ condition ]; then ...", a shortcut for > > /usr/bin/test. > > Nope, not correct. OK: ... another form of /usr/bin/test. :-) Bye... Dirk -- Dirk Heinrichs | Tel: +49 (0)162 234 3408 Configuration Manager | Fax: +49 (0)211 47068 111 Capgemini Deutschland | Mail: dirk.heinrichs@capgemini.com Hambornerstraße 55 | Web: http://www.capgemini.com D-40472 Düsseldorf | ICQ#: 110037733 GPG Public Key C2E467BB | Keyserver: www.keyserver.net [-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 11:02 ` Alexander Skwar 2006-07-25 12:11 ` Dirk Heinrichs @ 2006-07-25 12:26 ` Hagen Soengen 2006-07-25 12:20 ` Neil Bothwick 1 sibling, 1 reply; 27+ messages in thread From: Hagen Soengen @ 2006-07-25 12:26 UTC (permalink / raw To: gentoo-user On Tue, 25 Jul 2006 13:02:48 +0200 Alexander Skwar <listen@alexander.skwar.name> wrote: > Dirk Heinrichs wrote: > > Am Dienstag, 25. Juli 2006 11:00 schrieb ext Arnau Bria: > > > >> I've seen a file named "[" in my /usr/bin ... > >> [...] > >> > >> does any one know what could it be?¿ > > > > It's the [ from "if [ condition ]; then ...", a shortcut for /usr/bin/test. > > Nope, not correct. > > [09:39:58 vz6tml@dewup-ww02:~] $ type [ > [ is a shell builtin > [13:01:25 vz6tml@dewup-ww02:~] $ type test > test is a shell builtin > > And actually /usr/bin/[ and /usr/bin/test aren't even the same: > > [13:01:56 vz6tml@dewup-ww02:~] $ ls -la /usr/bin/{[,test} > -rwxr-xr-x 1 root root 24852 27. Jun 09:34 /usr/bin/[ > -rwxr-xr-x 1 root root 22784 27. Jun 09:34 /usr/bin/test > > I wonder where the differences are. I would've expected that test and [ > were hardlinks. # /usr/bin/[ /usr/bin/[: missing ']' # /usr/bin/test <no output> # You see? They cant be the same, because the closing "]" is needed by /usr/bin[ and not by /usr/bin/test Hagen -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 12:26 ` Hagen Soengen @ 2006-07-25 12:20 ` Neil Bothwick 2006-07-25 12:26 ` Mauro Faccenda 0 siblings, 1 reply; 27+ messages in thread From: Neil Bothwick @ 2006-07-25 12:20 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 619 bytes --] On Tue, 25 Jul 2006 12:26:53 +0000, Hagen Soengen wrote: > > I wonder where the differences are. I would've expected that test and > > [ were hardlinks. > > # /usr/bin/[ > /usr/bin/[: missing ']' > # /usr/bin/test > <no output> > # > > You see? They cant be the same, because the closing "]" is needed > by /usr/bin[ and not by /usr/bin/test It's quite common for a program to change its behaviour according to the name used to run it. For example, zcat and gunzip are links to gzip, yet the three programs behave differently. -- Neil Bothwick Stupid user error. Terminate user (Y/n) ? [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 12:20 ` Neil Bothwick @ 2006-07-25 12:26 ` Mauro Faccenda 2006-07-25 13:16 ` Neil Bothwick 0 siblings, 1 reply; 27+ messages in thread From: Mauro Faccenda @ 2006-07-25 12:26 UTC (permalink / raw To: gentoo-user; +Cc: Neil Bothwick On Tuesday 25 July 2006 09:20, Neil Bothwick wrote: > On Tue, 25 Jul 2006 12:26:53 +0000, Hagen Soengen wrote: > > > I wonder where the differences are. I would've expected that test and > > > [ were hardlinks. > > > > # /usr/bin/[ > > /usr/bin/[: missing ']' > > # /usr/bin/test > > <no output> > > # > > > > You see? They cant be the same, because the closing "]" is needed > > by /usr/bin[ and not by /usr/bin/test > > It's quite common for a program to change its behaviour according to the > name used to run it. For example, zcat and gunzip are links to gzip, yet > the three programs behave differently. but this isn't the case: $ sha1sum /usr/bin/\[ /usr/bin/test 2d3a938b84db7107e323ac85a9bf4f351721da7b /usr/bin/[ 1b126dd3e41a2a9d4554879647f73fdf49d29479 /usr/bin/test $ sha1sum /bin/zcat /bin/gzip /bin/gunzip 708011af43a41f6e3120e96eacb6ac4bba8717ee /bin/zcat 708011af43a41f6e3120e96eacb6ac4bba8717ee /bin/gzip 708011af43a41f6e3120e96eacb6ac4bba8717ee /bin/gunzip []'s .m -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 12:26 ` Mauro Faccenda @ 2006-07-25 13:16 ` Neil Bothwick 2006-07-25 13:41 ` Alan McKinnon ` (2 more replies) 0 siblings, 3 replies; 27+ messages in thread From: Neil Bothwick @ 2006-07-25 13:16 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 748 bytes --] On Tue, 25 Jul 2006 09:26:52 -0300, Mauro Faccenda wrote: > > > You see? They cant be the same, because the closing "]" is needed > > > by /usr/bin[ and not by /usr/bin/test > > > > It's quite common for a program to change its behaviour according to > > the name used to run it. For example, zcat and gunzip are links to > > gzip, yet the three programs behave differently. > > but this isn't the case: I was disagreeing with the "cant be the same" comment. I know they are different files, but the slightly different behaviour is insufficient reason for that. Alexander asked why one was not a link to the other, I'd like to know too, but this isn't the reason. -- Neil Bothwick Top Oxymorons Number 47: Act naturally [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 13:16 ` Neil Bothwick @ 2006-07-25 13:41 ` Alan McKinnon 2006-07-25 13:57 ` Alexander Skwar ` (2 more replies) 2006-07-25 13:59 ` Alexander Skwar 2006-07-25 14:35 ` Etaoin Shrdlu 2 siblings, 3 replies; 27+ messages in thread From: Alan McKinnon @ 2006-07-25 13:41 UTC (permalink / raw To: gentoo-user On Tue, 2006-07-25 at 14:16 +0100, Neil Bothwick wrote: > On Tue, 25 Jul 2006 09:26:52 -0300, Mauro Faccenda wrote: > > > > > You see? They cant be the same, because the closing "]" is needed > > > > by /usr/bin[ and not by /usr/bin/test > > > > > > It's quite common for a program to change its behaviour according to > > > the name used to run it. For example, zcat and gunzip are links to > > > gzip, yet the three programs behave differently. > > > > but this isn't the case: > > I was disagreeing with the "cant be the same" comment. I know they are > different files, but the slightly different behaviour is insufficient > reason for that. Alexander asked why one was not a link to the other, I'd > like to know too, but this isn't the reason. For such a simple question, this sure is generating a lot of traffic :-) The answer is simple: 'test' is a bash builtin. When a bash script executes 'test', it is not /usr/bin/test that runs, but a function internal to bash. /usr/bin/test/ is provided for environments that want to run bash scripts that use test but bash is not the shell in use. test and [ are not links to each other as they have different syntax (the closing ]), so they cannot be the same command. If they were linked, one of them would fail on execution with invalid syntax errors alan -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 13:41 ` Alan McKinnon @ 2006-07-25 13:57 ` Alexander Skwar 2006-07-25 14:18 ` Etaoin Shrdlu 2006-07-25 14:26 ` Neil Bothwick 2 siblings, 0 replies; 27+ messages in thread From: Alexander Skwar @ 2006-07-25 13:57 UTC (permalink / raw To: gentoo-user Alan McKinnon wrote: > On Tue, 2006-07-25 at 14:16 +0100, Neil Bothwick wrote: >> On Tue, 25 Jul 2006 09:26:52 -0300, Mauro Faccenda wrote: >> >> > > > You see? They cant be the same, because the closing "]" is needed >> > > > by /usr/bin[ and not by /usr/bin/test >> > > >> > > It's quite common for a program to change its behaviour according to >> > > the name used to run it. For example, zcat and gunzip are links to >> > > gzip, yet the three programs behave differently. >> > >> > but this isn't the case: >> >> I was disagreeing with the "cant be the same" comment. I know they are >> different files, but the slightly different behaviour is insufficient >> reason for that. Alexander asked why one was not a link to the other, I'd >> like to know too, but this isn't the reason. > > For such a simple question, this sure is generating a lot of traffic :-) > > The answer is simple: > > 'test' is a bash builtin. When a bash script executes 'test', it is > not /usr/bin/test that runs, but a function internal to bash. True. Same for [. > /usr/bin/test/ is provided for environments that want to run bash > scripts that use test but bash is not the shell in use. Nothing to argue here. > test and [ are not links to each other as they have different syntax > (the closing ]), so they cannot be the same command. That's not true. /usr/bin/[ and /usr/bin/test *COULD* be the same commands. If a program is invoked, it gets in $0 the name the user has used to call the program. Depending on this name/value, the program could behave differntly. > If they were > linked, one of them would fail on execution with invalid syntax errors Wrong. Alexander Skwar -- The politician is someone who deals in man's problems of adjustment. To ask a politician to lead us is to ask the tail of a dog to lead the dog. -- Buckminster Fuller -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 13:41 ` Alan McKinnon 2006-07-25 13:57 ` Alexander Skwar @ 2006-07-25 14:18 ` Etaoin Shrdlu 2006-07-25 14:33 ` Alan McKinnon 2006-07-25 14:26 ` Neil Bothwick 2 siblings, 1 reply; 27+ messages in thread From: Etaoin Shrdlu @ 2006-07-25 14:18 UTC (permalink / raw To: gentoo-user On Tuesday 25 July 2006 15:41, Alan McKinnon wrote: > The answer is simple: > > 'test' is a bash builtin. When a bash script executes 'test', it is > not /usr/bin/test that runs, but a function internal to bash. > > /usr/bin/test/ is provided for environments that want to run bash > scripts that use test but bash is not the shell in use. This makes sense. > test and [ are not links to each other as they have different syntax > (the closing ]), so they cannot be the same command. If they were > linked, one of them would fail on execution with invalid syntax errors This is not 100% true. As Neil Bothwick said, *the same program* can behave differently based on the name it was invoked with, so [ could very well have been implemented as a link to test (or viceversa), but this is not the case, as you can see with a ls -l /usr/bin/test /usr/bin/[ -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 14:18 ` Etaoin Shrdlu @ 2006-07-25 14:33 ` Alan McKinnon 2006-07-25 15:06 ` Neil Bothwick ` (3 more replies) 0 siblings, 4 replies; 27+ messages in thread From: Alan McKinnon @ 2006-07-25 14:33 UTC (permalink / raw To: gentoo-user On Tue, 2006-07-25 at 16:18 +0200, Etaoin Shrdlu wrote: > > test and [ are not links to each other as they have different syntax > > (the closing ]), so they cannot be the same command. If they were > > linked, one of them would fail on execution with invalid syntax > errors > > This is not 100% true. As Neil Bothwick said, *the same program* can > behave differently based on the name it was invoked with, so [ could > very well have been implemented as a link to test (or viceversa), but > this is not the case, as you can see with a > ls -l /usr/bin/test /usr/bin/[ Um, no. Read my post again. The command 'test' and the command '[' have *different* syntax so cannot possible be links to each other and still have it work. The command does behave differently depending on the name it is called with, but this does not change the syntax used on the command line that invokes it. alan -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 14:33 ` Alan McKinnon @ 2006-07-25 15:06 ` Neil Bothwick 2006-07-25 15:21 ` Etaoin Shrdlu ` (2 subsequent siblings) 3 siblings, 0 replies; 27+ messages in thread From: Neil Bothwick @ 2006-07-25 15:06 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 403 bytes --] On Tue, 25 Jul 2006 16:33:19 +0200, Alan McKinnon wrote: > Um, no. Read my post again. The command 'test' and the command '[' have > *different* syntax so cannot possible be links to each other and still > have it work. if [ $(basename $0) == "[" ] then #parse for trailing ] else #parse to end of line fi -- Neil Bothwick Help! I've fallen and I can't get down! - James Brown [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 14:33 ` Alan McKinnon 2006-07-25 15:06 ` Neil Bothwick @ 2006-07-25 15:21 ` Etaoin Shrdlu 2006-07-25 18:09 ` Alexander Skwar 2006-07-25 18:24 ` Daniel da Veiga 3 siblings, 0 replies; 27+ messages in thread From: Etaoin Shrdlu @ 2006-07-25 15:21 UTC (permalink / raw To: gentoo-user On Tuesday 25 July 2006 16:33, Alan McKinnon wrote: > Um, no. Read my post again. The command 'test' and the command '[' > have *different* syntax so cannot possible be links to each other and > still have it work. The command does behave differently depending on > the name it is called with, but this does not change the syntax used > on the command line that invokes it. There are two cases: [1] syntax checking is done by the shell, or [2] syntax checking is done by the program. The interesting case is [2]. Let's make an oversimplified example. Suppose you want the commands "commandA" and "commandB". The syntax for commandA is commandA <arg1> <arg2> but commandB takes a third argument, so you invoke it with commandB <arg1> <arg2> <arg3> This, to me, qualifies as "*different* syntax". Here is how those checks can be implemented _using the same program_. #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { char *progname; /* the following should actually extract the basename of the program from argv[0], but to keep things simple let's assume that the shell does this for us */ progname = argv[0]; if (strcmp(progname, "commandA") == 0) { /* check that we have TWO arguments */ if (argc == 3) { printf("Ok, running as commandA with two arguments\n"); exit(0); } else { printf("Running as commandA, but with the wrong number of arguments\n"); exit(1); } } else if (strcmp(progname, "commandB") == 0) { /* check that we have THREE arguments */ if (argc == 4) { printf("Ok, running as commandB with three arguments\n"); exit(0); } else { printf("Running as commandB, but with the wrong number of arguments\n"); exit(1); } } else { printf("Bad program name!\n"); exit(1); } } In fact, as I said in a previous post, [ and test are built from the same source file, and the "[" vs. "test" difference is used only to check for proper syntax. -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 14:33 ` Alan McKinnon 2006-07-25 15:06 ` Neil Bothwick 2006-07-25 15:21 ` Etaoin Shrdlu @ 2006-07-25 18:09 ` Alexander Skwar 2006-07-25 18:24 ` Daniel da Veiga 3 siblings, 0 replies; 27+ messages in thread From: Alexander Skwar @ 2006-07-25 18:09 UTC (permalink / raw To: gentoo-user Alan McKinnon schrieb: > On Tue, 2006-07-25 at 16:18 +0200, Etaoin Shrdlu wrote: >> > test and [ are not links to each other as they have different syntax >> > (the closing ]), so they cannot be the same command. If they were >> > linked, one of them would fail on execution with invalid syntax >> errors >> >> This is not 100% true. As Neil Bothwick said, *the same program* can >> behave differently based on the name it was invoked with, so [ could >> very well have been implemented as a link to test (or viceversa), but >> this is not the case, as you can see with a >> ls -l /usr/bin/test /usr/bin/[ > > Um, no. Uhm, *YES*. > Read my post again. You better do so. > The command 'test' and the command '[' have > *different* syntax Yes. > so cannot possible be links to each other Why not? > The command does behave differently depending on the name > it is called with, but this does not change the syntax used on the > command line that invokes it. What are you talking about? Of course the program could have a different syntax. For example, compare the syntax that zipinfo and unzip have. Alexander Skwar -- Delta: The kids will love our inflatable slides. -- David Letterman -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 14:33 ` Alan McKinnon ` (2 preceding siblings ...) 2006-07-25 18:09 ` Alexander Skwar @ 2006-07-25 18:24 ` Daniel da Veiga 3 siblings, 0 replies; 27+ messages in thread From: Daniel da Veiga @ 2006-07-25 18:24 UTC (permalink / raw To: gentoo-user On 7/25/06, Alan McKinnon <alan@linuxholdings.co.za> wrote: > On Tue, 2006-07-25 at 16:18 +0200, Etaoin Shrdlu wrote: > > > test and [ are not links to each other as they have different syntax > > > (the closing ]), so they cannot be the same command. If they were > > > linked, one of them would fail on execution with invalid syntax > > errors > > > > This is not 100% true. As Neil Bothwick said, *the same program* can > > behave differently based on the name it was invoked with, so [ could > > very well have been implemented as a link to test (or viceversa), but > > this is not the case, as you can see with a > > ls -l /usr/bin/test /usr/bin/[ > > Um, no. Read my post again. The command 'test' and the command '[' have > *different* syntax so cannot possible be links to each other and still > have it work. The command does behave differently depending on the name > it is called with, but this does not change the syntax used on the > command line that invokes it. > Why not? The syntax is simply based on tests performed over the arguments received, the name of the program is one of those arguments, what stop the programmer to test the name and change the syntax accourding with that name? Many of my scripts behave differently accourding with the name it was called. That allows me to write simple tests, symlink the same program to different names and have different behavior/syntax, much better than copy the same file and edit it. -- Daniel da Veiga Computer Operator - RS - Brazil -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCM/IT/P/O d-? s:- a? C++$ UBLA++ P+ L++ E--- W+++$ N o+ K- w O M- V- PS PE Y PGP- t+ 5 X+++ R+* tv b+ DI+++ D+ G+ e h+ r+ y++ ------END GEEK CODE BLOCK------ -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 13:41 ` Alan McKinnon 2006-07-25 13:57 ` Alexander Skwar 2006-07-25 14:18 ` Etaoin Shrdlu @ 2006-07-25 14:26 ` Neil Bothwick 2 siblings, 0 replies; 27+ messages in thread From: Neil Bothwick @ 2006-07-25 14:26 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 1358 bytes --] On Tue, 25 Jul 2006 15:41:56 +0200, Alan McKinnon wrote: > The answer is simple: Maye, but this isn't it. > 'test' is a bash builtin. When a bash script executes 'test', it is > not /usr/bin/test that runs, but a function internal to bash. test and [ are both Bash builtins, but there are also [ and test commands in /usr/bin. This has nothing to do with the builtins. > /usr/bin/test/ is provided for environments that want to run bash > scripts that use test but bash is not the shell in use. Those scripts can also use /usr/bin/[ > test and [ are not links to each other as they have different syntax > (the closing ]), so they cannot be the same command. If they were > linked, one of them would fail on execution with invalid syntax errors That's wrong, as explained in my previous response that you quoted. A command receives the name it was invoked with as one of its arguments. So it is possible for a command to operate differently according to the name used to run it, such as the gzip/gunzip/zcat example I gave earlier, or the hundreds of commends in netpbm that are mainly symlinks to a few core commands. It's possible to do this with scripts too, I have a number of scripts that act differently according to the name used to run them. -- Neil Bothwick Plagarism prohibited. Derive carefully. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 13:16 ` Neil Bothwick 2006-07-25 13:41 ` Alan McKinnon @ 2006-07-25 13:59 ` Alexander Skwar 2006-07-25 14:35 ` Etaoin Shrdlu 2 siblings, 0 replies; 27+ messages in thread From: Alexander Skwar @ 2006-07-25 13:59 UTC (permalink / raw To: gentoo-user Neil Bothwick wrote: > On Tue, 25 Jul 2006 09:26:52 -0300, Mauro Faccenda wrote: > >> > > You see? They cant be the same, because the closing "]" is needed >> > > by /usr/bin[ and not by /usr/bin/test >> > >> > It's quite common for a program to change its behaviour according to >> > the name used to run it. For example, zcat and gunzip are links to >> > gzip, yet the three programs behave differently. >> >> but this isn't the case: > > I was disagreeing with the "cant be the same" comment. I know they are > different files, but the slightly different behaviour is insufficient > reason for that. Alexander asked why one was not a link to the other, I'd > like to know too, but this isn't the reason. Yes, you're right, [ and test *COULD* be the same command, just like gzip and gunzip are the same command, but the coreutils makers seem to have decided otherwise. It's not that important to me, if it were, I'd ask the coreutils makers and not some 3rd party. :) Anyway, on other systems (HP-UX, Solaris 8), there isn't even a /usr/bin/[ - there's just /usr/bin/test. Alexander Skwar -- May those that love us love us; and those that don't love us, may God turn their hearts; and if he doesn't turn their hearts, may he turn their ankles so we'll know them by their limping. -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 13:16 ` Neil Bothwick 2006-07-25 13:41 ` Alan McKinnon 2006-07-25 13:59 ` Alexander Skwar @ 2006-07-25 14:35 ` Etaoin Shrdlu 2 siblings, 0 replies; 27+ messages in thread From: Etaoin Shrdlu @ 2006-07-25 14:35 UTC (permalink / raw To: gentoo-user On Tuesday 25 July 2006 15:16, Neil Bothwick wrote: > I was disagreeing with the "cant be the same" comment. I know they are > different files, but the slightly different behaviour is insufficient > reason for that. Alexander asked why one was not a link to the other, > I'd like to know too, but this isn't the reason. [slowly getting OT...] Looking at coreutils sources, it turns out that there are two files: test.c and lbracket.c. test.c is the actual program, and lbracket.c is as follows: $ cat lbracket.c #define LBRACKET 1 #include "test.c" so, test.c does all the work. After taking a quick look at the code, seems that the only times LBRACKET is checked are in the following fragments: ... /* The official name of this program (e.g., no `g' prefix). */ #if LBRACKET # define PROGRAM_NAME "[" #else # define PROGRAM_NAME "test" #endif ... if (LBRACKET) { /* Recognize --help or --version, but only when invoked in the "[" form, and when the last argument is not "]". POSIX allows "[ --help" and "[ --version" to have the usual GNU behavior, but it requires "test --help" and "test --version" to exit silently with status 1. */ if (margc < 2 || !STREQ (margv[margc - 1], "]")) { parse_long_options (margc, margv, PROGRAM_NAME, GNU_PACKAGE, VERSION, usage, AUTHORS, (char const *) NULL); test_syntax_error (_("missing `]'\n"), NULL); } --margc; } argc = margc; pos = 1; ... Again, the above could have been implemented by looking at argv[0]. -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
* Re: [gentoo-user] strange [ file 2006-07-25 9:00 [gentoo-user] strange [ file Arnau Bria ` (3 preceding siblings ...) 2006-07-25 9:17 ` Dirk Heinrichs @ 2006-07-25 9:20 ` Neil Bothwick 2006-07-25 9:34 ` [gentoo-user] " Marco Costa 5 siblings, 0 replies; 27+ messages in thread From: Neil Bothwick @ 2006-07-25 9:20 UTC (permalink / raw To: gentoo-user [-- Attachment #1: Type: text/plain, Size: 347 bytes --] On Tue, 25 Jul 2006 11:00:38 +0200, Arnau Bria wrote: > I've seen a file named "[" in my /usr/bin ... [ is a synonym for the test command, see man test for details. This file isn't normally used, because [ and test are builtins in Bash. -- Neil Bothwick Some day my ship will come in, but with my luck, I'll be at the airport. [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 189 bytes --] ^ permalink raw reply [flat|nested] 27+ messages in thread
* [gentoo-user] Re: strange [ file 2006-07-25 9:00 [gentoo-user] strange [ file Arnau Bria ` (4 preceding siblings ...) 2006-07-25 9:20 ` Neil Bothwick @ 2006-07-25 9:34 ` Marco Costa 5 siblings, 0 replies; 27+ messages in thread From: Marco Costa @ 2006-07-25 9:34 UTC (permalink / raw To: gentoo-user Arnau Bria wrote: > I've seen a file named "[" in my /usr/bin ... > ... > does any one know what could it be?¿ > thanks in advance. It is the test application/tool. Try 'info test'. Regards, Marco -- gentoo-user@gentoo.org mailing list ^ permalink raw reply [flat|nested] 27+ messages in thread
end of thread, other threads:[~2006-07-25 18:35 UTC | newest] Thread overview: 27+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-07-25 9:00 [gentoo-user] strange [ file Arnau Bria 2006-07-25 9:06 ` Dale 2006-07-25 9:13 ` Christoph Eckert 2006-07-25 9:14 ` Richard Fish 2006-07-25 9:36 ` Arnau Bria 2006-07-25 9:55 ` Neil Bothwick 2006-07-25 11:00 ` Alexander Skwar 2006-07-25 9:17 ` Dirk Heinrichs 2006-07-25 11:02 ` Alexander Skwar 2006-07-25 12:11 ` Dirk Heinrichs 2006-07-25 12:26 ` Hagen Soengen 2006-07-25 12:20 ` Neil Bothwick 2006-07-25 12:26 ` Mauro Faccenda 2006-07-25 13:16 ` Neil Bothwick 2006-07-25 13:41 ` Alan McKinnon 2006-07-25 13:57 ` Alexander Skwar 2006-07-25 14:18 ` Etaoin Shrdlu 2006-07-25 14:33 ` Alan McKinnon 2006-07-25 15:06 ` Neil Bothwick 2006-07-25 15:21 ` Etaoin Shrdlu 2006-07-25 18:09 ` Alexander Skwar 2006-07-25 18:24 ` Daniel da Veiga 2006-07-25 14:26 ` Neil Bothwick 2006-07-25 13:59 ` Alexander Skwar 2006-07-25 14:35 ` Etaoin Shrdlu 2006-07-25 9:20 ` Neil Bothwick 2006-07-25 9:34 ` [gentoo-user] " Marco Costa
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox