Another script question.

Hi,
First off I usually script in the bash shell.
Ok, in my script I am checking to see if the filename has a .txt extension.
So I was trying:

if [ ! -e "*txt" ]
then
    echo "Must contain a valid .txt extension"
fi

and

if [ "-f" -eq *[txt] ]
then
    echo "Must contain a valid .txt extension"
fi

But no go the first example sort of works but it always echo out the statement.

added code tags for readability --oombera

Hi again,
OK - I figured it out on my own, this is funny when this happens!

if [ "-f" = "*txt" ]
then
    echo 
fi

But thanks for trying!

added code tags for readability --oombera

Actually this isn't really working:

I used:

if [ ! -e "$1" ]
then
    echo "Database file \"$1\" does not exist!"
    exit 1
elif [ ! -e "$1" ]
then
    echo "Database file \"$1\" does not exist!"
    exit 1
fi

Even if the file in my dir has is a .txt it prompt for a txt extension.

if [ ! -e "$1" ]
then
    echo "Database file \"$1\" does not exist!"
    exit 1
elif [ ! -e "$1" ]
then
    echo "Database file \"$1\" does not exist!"
    exit 1
fi

theA

added code tags for readability --oombera

Maybe you could do something like this to check for an extension:

echo $1 | grep ".txt$" 1>/dev/null
status=$?

if [ $status -eq 0 ] 
then
	echo "found .txt extension"
else
	echo "not found"
fi

Not sure if that is what you are asking...?

This is wat I have, I used "elif" before but it worked the same. Ok the first 2 if statements work but the last 2 don't. For example here are the files in your dir:
10 11.txt 12 14.txt

When you run this script: (called script1)

script1 10 - it doesn't prompt for txt extension!

It should now say "Must have txt extension!"

I don't know what I am doing wrong, this seems so simple but I can't hack it!

Please help,

theA

if [ "$#" -eq 0 ]
then
    echo "Name required!"
    exit 1
fi

if [ "$#" -gt 1 ]
then
    echo "Only one please!!"
    exit 1
fi

if [ ! -e "$1" ]
then
    echo "Database file \"$1\" does not exist!"
    exit 1
fi

if [ "-f" = ".txt$" ]
then
echo "Database files must contain a "txt" extension!"
    exit 1

fi

added code tags for readability --oombera

This works for me in bash:

if [ ! -e $1 ]
then 
  echo "Database file \"$1\" does not exist!" 
  exit 1 
fi 

if [ ! `echo $1 | grep ".txt$"` ] 
then 
  echo "Database files must contain a "txt" extension!" 
  exit 1 
fi

added code tags for readability --oombera