[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug?

From: Bob Proulx
Subject: Re: Bug?
Date: Fri, 2 Feb 2001 14:14:09 -0700

> When using the test program as in the following:
>         if [ -f *.in ]; then
>             do something
>         fi
> This works fine as long as you have only one file with the extension =
> ".in", but when you have multiple files with the extension, it errors.
> Is this what was intended or is this really a bug?

Thanks for the report but that is not a bug.  That is the intended
behavior.  The shell expands the *.in before 'test' (aka '[' here)
ever gets a chance to see it.  You can verify this by using the echo
command to test this.

  echo [ -f *.in ]

Probably what you want is to loop through all of the files.

  for file in *.in; do
    if [ -f "$file" ]; then
      : do something

Note the quotes to preserve files with white space in them.

Or perhaps you just want to know if any .in files exist at all in
which case you could perhaps do something like this.

  if [ -n "`echo *.in`" ]; then
    : do something

> This may be a bug but I am not sure if it was intended to work this way =
> (only because I am used to SCO *nix flavor)

I find it hard to believe that SCO behaves differently.  The last SCO
system I used was standard with regards to Bourne shell behavior.
This behavior is dictated not by the test application program but by
the command shell that is interpreting the file, which I expect to be
either the Bourne shell, ksh, or bash, and all behave the same with
regards to this operation.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]