Skip to content

Instantly share code, notes, and snippets.

@cuschk
Created July 8, 2016 11:30
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cuschk/2fe5e78059a8d886f948d6ee78cf7820 to your computer and use it in GitHub Desktop.
Save cuschk/2fe5e78059a8d886f948d6ee78cf7820 to your computer and use it in GitHub Desktop.
Bash: file base name and extension
#!/usr/bin/env bash
f='/path/to/example.txt'
base="${f##*/}"
echo $base
#=> example.txt
echo "${base%.*}"
#=> example
echo "${base##*.}"
#=> txt
@cuschk
Copy link
Author

cuschk commented Jul 8, 2016

@cuschk
Copy link
Author

cuschk commented Jul 8, 2016

Also see filename.zsh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment