bug-bash
[Top][All Lists]
Advanced

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

Re: test -f xxx???


From: Ben Logan
Subject: Re: test -f xxx???
Date: Fri, 31 May 2002 12:21:55 -0400
User-agent: Mutt/1.2.5i

On Fri, May 31, 2002 at 11:22:33AM +0200, Stefan Marquardt wrote:
> test -d /home/work/man??? works on all OS except Linux
> (gnu-shell-utils)
> 
> If there are more than one man??? directorys then i get the error
> "too many parameters"
> 
> Is this an bug or not ?

I'm not an expert, so I'd be glad for someone to correct me if I'm
wrong, but here goes:

In the output from "help test" it says 'test [expr]'.  When you run

$ test -d /home/work/man???

filename expansion occurs first, so test sees (for example)

$ test -d /home/work/man001 /home/work/man002 /home/work/manabc

or whatever matches the wildcard expression.  Clearly that is not what
'test' expects.  This would work (although it might not do what you
want):

$ for i in /home/work/man???; do test -d $i; done

That's probably what I'd do, but you could also do something crazy
like:

test $(count=0;for i in *; do test $count -eq 0 && echo -n "-d $i " || echo -n 
"-a -d $i "; count=1;done)

Which would return "0" only if all the entries which match
/home/work/man??? are all directories.

One more thing: remember that if you type "test" you are probably
getting the bash builtin command.  If you want the standalone program,
you need to type the path (probably /bin/test).  They behave pretty
much the same, I think, but there may be some differences.

Hope this helps,
Ben

-- 
Ben Logan: ben at wblogan dot net
OpenPGP Key KeyID: A1ADD1F0

Anyone stupid enough to be caught by the police is probably guilty.



reply via email to

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