[NTLUG:Discuss] Shortcuts

Douglas Scott dcscott1 at home.com
Fri Aug 24 19:52:10 CDT 2001


----- Original Message -----
From: "Steve Baker" <sjbaker1 at airmail.net>
To: <discuss at ntlug.org>
Sent: Friday, August 24, 2001 9:09 PM
Subject: Re: [NTLUG:Discuss] Shortcuts


> But either way, the biggest problem I find with newbies who do that is
that
> the very first C program they write is invariably called "test.c" and
compiles
> to "test".  If "." is in their search path at the beginning of the list
then
> their program works OK - but a bunch of system commands that are really
shell
> scripts break mysteriously because they have things like:
>
>     if test "$1" = "-a" ; then ...whatever...
>
> ...and the users' own "test" program gets run instead of the system "test"
> program - with "interesting" consequences.  I knew a guy at work who did
exactly
> that and couldn't get the "spell" command to work.  We scratched our heads
for
> weeks before we realised he'd put a 'test' program into one of his search
path
> directories.  What's amazing is that he only noticed it with 'spell' and
not
> any of the other dozens of system programs that call 'test'.

Probably because 'spell' was the only script that actually used 'test'
instead of '['.  In scripts instead of

    if test "$1" = "-a" ; then something

you normally see

    if [ "$1" = "-a" ]; then something

or even

   [ "$1" = "-a" ] && something.

'test' and '[' are hardlinked to the same file.  This problem would only
effect scripts that actually use 'test'.

I think the reverse problem is much more common for newbies.  I can well
remember the hour or two I spent wondering why my 'test' program would do
nothing no matter what I told it to print.

Shortly afterwards I learned about the 'which' command, which can be quite
enlightening in these kind of situations.

Doug Scott




More information about the Discuss mailing list