Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewgrant/e5826ebb2924ea37c7802aa93e3d637f to your computer and use it in GitHub Desktop.
Save andrewgrant/e5826ebb2924ea37c7802aa93e3d637f to your computer and use it in GitHub Desktop.
Bash expansions to extract file components and extension from paths
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