Get filename and extension in Shell Script
#!/bin/bash
filePath="~/Desktop/GETTING THINGS DONE.pdf"
filename=$(basename "$filePath")
extension="${filename##*.}"
filename="${filename%.*}"
echo "$filename"
echo "$extension"
output:
FileName: GETTING THINGS DONE
FileExtension: pdf
Written by CrazyApi
Related protips
1 Response
Awesome! This also helped me understand the use of ## and % with the *.
Still lot more to learn...
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Shell
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#