I want to get the filename (without extension) and the extension separately.
The best solution I found so far is:
NAME=`echo \"$FILE\" | cut -d\'.\'
You can use basename.
Example:
$ basename foo-bar.tar.gz .tar.gz
foo-bar
You do need to provide basename with the extension that shall be removed, however if you are always executing tar
with -z
then you know the extension will be .tar.gz
.
This should do what you want:
tar -zxvf $1
cd $(basename $1 .tar.gz)