Created
July 9, 2020 14:06
-
-
Save andrewgrant/e5826ebb2924ea37c7802aa93e3d637f to your computer and use it in GitHub Desktop.
Bash expansions to extract file components and extension from paths
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From | |
https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash | |
~% FILE="example.tar.gz" | |
~% echo "${FILE%%.*}" | |
example | |
~% echo "${FILE%.*}" | |
example.tar | |
~% echo "${FILE#*.}" | |
tar.gz | |
~% echo "${FILE##*.}" | |
gz | |
and | |
filename=$(basename -- "$fullpath") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment