View Single Post
  #4   (View Single Post)  
Old 3rd January 2012
sharris sharris is offline
Package Pilot
 
Join Date: Jun 2010
Posts: 146
Default

First off, this week is my first real try at shell scripting so excuse me for carrying on, I'm just a little excited. If anyone has tried this already, it's easy to over look the results but this old 1999 script IS working because it return/echo the files inside the brackets [.this file that file]

I remove the -z and placed cd /test_directory over the if/else statement. If no cd command is used it will return a list of what is in the directory the script is called from. It's a start but it shouldn't stop there.

The first problem is to get BSD not to generate the "No such file or directory" or "command not found" error because your results are in the bracket anyway.

Code:
./isEmpty.sh: line 10: [.this file that file]: command not found
file found
This cause the script to exit to the *else* statement telling you *file found* even if the directory is empty . That's all I figured out so far. How do you suppress or even turn-off shell scripting error? I would have no problem living with-out it since you can do that with (if/else) just like other programming languages. My guest is it will work just because of that.

Code:
cd /test_directory
if ["`ls`" ]
        then
        echo "no files found."
else
        echo "files found."
fi
Reply With Quote