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
Is there a better way to do this?
















if [ $(echo $ArchiveName | grep -i "tar$" ) ]
then
echo Test1: It is a tar file
else
echo Test1: It is a zip file
fi
that works for me. (i'm using unix, so put your -i back where it belongs)
Comment by digitalramble — January 19, 2007 @ 3:15 pm
Cripes.
You need a preview plugin
Comment by digitalramble — January 19, 2007 @ 3:16 pm
Thanks Cindy!
That works Great!
Comment by Brian — January 19, 2007 @ 3:41 pm