[gentoo-user] strange [ file

2006-07-25 Thread Arnau Bria
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Dale
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:

 [EMAIL PROTECTED] / # equery belongs [
 [ Searching for file(s) [ in *... ]
 sys-apps/coreutils-5.94-r1 (/usr/bin/[)
 [EMAIL PROTECTED] / #

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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Richard Fish

On 7/25/06, Arnau Bria [EMAIL PROTECTED] 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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Dirk Heinrichs
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: [EMAIL PROTECTED]
Hambornerstraße 55  | Web:  http://www.capgemini.com
D-40472 Düsseldorf  | ICQ#: 110037733
GPG Public Key C2E467BB | Keyserver: www.keyserver.net


pgpoZAiy2byWW.pgp
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Arnau Bria
On Tue, 25 Jul 2006 02:14:02 -0700
Richard Fish wrote:

 On 7/25/06, Arnau Bria [EMAIL PROTECTED] 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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Christoph Eckert

 does any one know what could it be?¿

AFAIK it's a synonym to »test«.


Best regards


ce

-- 
gentoo-user@gentoo.org mailing list



Re: [gentoo-user] strange [ file

2006-07-25 Thread Neil Bothwick
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.


signature.asc
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Alexander Skwar
Richard Fish wrote:
 On 7/25/06, Arnau Bria [EMAIL PROTECTED] 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



Re: [gentoo-user] strange [ file

2006-07-25 Thread 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.

[09:39:58 [EMAIL PROTECTED]:~] $ type [
[ is a shell builtin
[13:01:25 [EMAIL PROTECTED]:~] $ type test
test is a shell builtin

And actually /usr/bin/[ and /usr/bin/test aren't even the same:

[13:01:56 [EMAIL PROTECTED]:~] $ 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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Hagen Soengen
On Tue, 25 Jul 2006 13:02:48 +0200
Alexander Skwar [EMAIL PROTECTED] 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 [EMAIL PROTECTED]:~] $ type [
 [ is a shell builtin
 [13:01:25 [EMAIL PROTECTED]:~] $ type test
 test is a shell builtin
 
 And actually /usr/bin/[ and /usr/bin/test aren't even the same:
 
 [13:01:56 [EMAIL PROTECTED]:~] $ 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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Dirk Heinrichs
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: [EMAIL PROTECTED]
Hambornerstraße 55  | Web:  http://www.capgemini.com
D-40472 Düsseldorf  | ICQ#: 110037733
GPG Public Key C2E467BB | Keyserver: www.keyserver.net


pgpzWjxldo7tB.pgp
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Neil Bothwick
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.


signature.asc
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Neil Bothwick
On Tue, 25 Jul 2006 12:26:53 +, 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) ?


signature.asc
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Mauro Faccenda
On Tuesday 25 July 2006 09:20, Neil Bothwick wrote:
 On Tue, 25 Jul 2006 12:26:53 +, 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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Neil Bothwick
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


signature.asc
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Alan McKinnon
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Etaoin Shrdlu
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Alexander Skwar
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Alexander Skwar
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Etaoin Shrdlu
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Neil Bothwick
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.


signature.asc
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Alan McKinnon
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Etaoin Shrdlu
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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Neil Bothwick
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


signature.asc
Description: PGP signature


Re: [gentoo-user] strange [ file

2006-07-25 Thread Alexander Skwar

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



Re: [gentoo-user] strange [ file

2006-07-25 Thread Daniel da Veiga

On 7/25/06, Alan McKinnon [EMAIL PROTECTED] 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