Reputation:
What I'm looking for is something like:
if [ -f "filenam*" ]; then
...
fi
But the wildcard (*) causes problems.
I've also tried:
if [ `ls filenam* > /dev/null 2>&1` ]; then
...
fi
Which may work in other shells but doesn't appear to work in Bourne shell (sh).
Thanks for any help!
EDIT: Sorry, not C shell, Bourne shell (sh).
Upvotes: 2
Views: 1575
Reputation: 212248
Rather than using test -n $(ls filenam*)
, you might prefer:
if ls filenam* 2> /dev/null | grep . > /dev/null; then
...
fi
Upvotes: 2
Reputation: 37103
As this is csh, what about:
foreach i (`ls -d filenam*`)
...
end
Upvotes: 0
Reputation: 16358
I like this:
function first() { echo "$1" ; }
[ -e $(first filenam*) ] && echo "yes" || echo "no"
Upvotes: 0
Reputation: 13624
You were on the right track. Try this:
if [ ! -z `ls filenam*` ] ; then
...
fi
That will check whether ls returns anything.
Upvotes: 0
Reputation: 88796
Since this is C based, you probably need the glob command:
ls `glob filenam*`
Upvotes: 0