#!/bin/bash

# if $1 is a plain file, returns TRUE if the file has size 0, otherwise FALSE
# if $1 is a directory, returns TRUE if it has no files, otherwise FALSE

if [ $# -ne 1 ]
then
	echo "usage: isempty filename"
	exit 2
fi

FILENAME=$1

if test -d $FILENAME
then
	if [ $(ls -a $FILENAME |wc -l) -eq 2 ]
	then
	   	exit 0
	else
		exit 1
	fi
elif test -f $FILENAME
then
	# echo "isempty: $FILENAME is regular file"
	FILESIZE=$(ls -l $FILENAME | awk '{ print $5 }')
	# if [ $FILESIZE -eq 0 ]
	if test ! -s $FILENAME
	then
		exit 0
	else
		exit 1
	fi
else
	echo "isempty: $FILENAME is weird file"
	exit 2
fi

