What is wrong with this bash script?

It should say that test.zip is a zip file, but the if statments, which check for TAR in the file name, all return true… If I do this outside of an if statement, say at the shell prompt, it works correctly.

What is wrong with this statement:

[dos]
#$bash

ArchiveName=”test.zip”
cur_file=”test.zip”
echo “ArchiveName: $ArchiveName”

if [ $(echo $ArchiveName | grep “tar$” -i)=$ArchiveName ]
then
echo Test1: It is a tar file
else
echo Test1: It is a zip file
fi

if [ $(echo $ArchiveName | grep “tar.gz$” -i)=$ArchiveName ]
then
echo Test2: It is a tar file
else
echo Test2: It is a zip file
fi

if [ $(echo $ArchiveName | grep “tar$” -i)=$ArchiveName ] || [ $(echo “$ArchiveName” | grep “tar.gz$” -i)=$ArchiveName ]
then
echo Test3: It is a tar file
else
echo Test3: It is a zip file
fi

[/dos]

Is there a better way to do this?

3 Comments

Add a Comment

Your email address will not be published. Required fields are marked *