Created
May 11, 2014 01:40
-
-
Save huzhifeng/d039e7300d6900a50bae to your computer and use it in GitHub Desktop.
Extract filename, extension and dir in bash, Refer to http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
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
#!/bin/bash | |
full_path="/var/www/public/ch1.sec1.index.html" | |
dir=${full_path%/*} | |
filename=$(basename $full_path) | |
filename_with_ext=${full_path##*/} | |
filename_without_ext=${filename_with_ext%.*} | |
ext=${full_path##*.} | |
echo "Full path: $full_path" # /var/www/public/ch1.sec1.index.html | |
echo "Dir: $dir" # /var/www/public | |
echo "File name: $filename_with_ext" # ch1.sec1.index.html | |
echo "File name without ext: $filename_without_ext" # ch1.sec1.index | |
echo "Ext: $ext" # html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment