Some more probing might still be needed for the second solution, how a .tar.gz gets handled might depend on the programmer intent, could be different from a .gz hypothetically.
Because not every answer is as quick and straightforward as your example.
To get the last 3 characters, do `echo ${foo: -3}`. Are you trying to get the file extension though? What if the extension is not 3 characters e.g. `foo.jpeg`? You then want to do `${foo##*.}`