Skip to content

Instantly share code, notes, and snippets.

@cuschk
Created July 8, 2016 11:30
Show Gist options
  • Select an option

  • Save cuschk/2fe5e78059a8d886f948d6ee78cf7820 to your computer and use it in GitHub Desktop.

Select an option

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

cuschk commented Jul 8, 2016

Copy link
Copy Markdown
Author

@cuschk

cuschk commented Jul 8, 2016

Copy link
Copy Markdown
Author

Also see filename.zsh.

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