How would I get just the filename without the extension and no path?
The following gives me no extension but I still have the path attached:
source_file_filename_no_ext=${source_file%.*}
How would I get just the filename without the extension and no path?
The following gives me no extension but I still have the path attached:
source_file_filename_no_ext=${source_file%.*}
Most UNIXes have a basename
executable for just that purpose.
pax> a=/tmp/file.txt
pax> b=$(basename $a)
pax> echo $b
file.txt
If you want a bash-only solution, you can start with:
pax> a=/tmp/xx/file.tar.gz
pax> xpath=${a%/*}
pax> xbase=${a##*/}
pax> xfext=${xbase##*.}
pax> xpref=${xbase%.*}
pax> echo;echo path=${xpath};echo pref=${xpref};echo ext=${xfext}
path=/tmp/xx
pref=file.tar
ext=gz
That little snippet sets xpath
(the file path), xpref
(the file prefix) and xfext
(the file extension).
$ source_file_filename_no_ext=${source_file%.*}
$ echo ${source_file_filename_no_ext##*/}