Results 1 to 5 of 5
I'm trying to convert a script from Unix over to SuSE Linux. Most of it is ok, but the following is giving me problems
Code:
#!/bin/bash
if [ -f /apps/v1.0/import/* ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 05-16-2005 #1Just Joined!
- Join Date
- May 2005
- Posts
- 1
Checking to see if there are files in a directory
I'm trying to convert a script from Unix over to SuSE Linux. Most of it is ok, but the following is giving me problems
Basically when I run it I get a binary operator expected error if there is more than one file in the directory.Code:#!/bin/bash if [ -f /apps/v1.0/import/* ] then #Do something else #Do something else fi
So could someone recomend a way to test if there are files in a directory.
Thanks
- 05-16-2005 #2
You could try this:
Code:if [ `ls | wc -w` -ge 0 ]; then do something fi
- 05-17-2005 #3Linux Enthusiast
- Join Date
- Jan 2005
- Posts
- 575
Re: Checking to see if there are files in a directory
How did the original script do it ?
Originally Posted by Monday
- 05-17-2005 #4Linux Engineer
- Join Date
- Mar 2005
- Posts
- 1,431
And which language was the unix script written in? Maybe you can use the same on linux?
- 05-17-2005 #5Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
change the if statement to use test instead of square brackets, then the presence of additional files will be ignored:
The original script is badly coded, BTW, because it won't work on UNIX either if more than one file is present.Code:if test -f /apps/v1.0/import/*


Reply With Quote
