Your criteria are wrong. *.* will return all files with extensions. For example, foo.gz. Now you're checking the following, in pseudocode:
if [ foo.gz.gz does not exist ]
compress foo.gz to foo.gz.gz
else
don't overwrite foo.gz.gz
So, your test command will always branch off to compressing something because the test will always evaluate to true. In the end you'll always overwrite your files, because "$f.gz" will expand to foo.gz.gz.
If your real requirement is to match everything but .gz files in your current directory, Bash has easier ways to do that, e.g. by using the extglob option and negation.
#!/bin/bash
FOLDER=$1
shopt -s extglob
cd "$FOLDER"
for f in !(*.gz); do
if [[ ! -d "$f" ]]; then
gzip "$f"
fi
done
You can include a check for whether the file name returned isn't actually a directory—unless you want to compress directories as well.
But actually, Linux gives you better tools to find files matching certain criteria. To (recursively) find all files that don't end with .gz and compress them:
find /some/where -type f ! -iname '*.gz' -exec gzip '{}' \;
If you don't want recursion:
find /some/where -type f -maxdepth 1 ! -iname '*.gz' -exec gzip '{}' \;
cd "$FOLDER"andgzip "$f". – Daniel Andersson Feb 20 at 13:10