Created
September 11, 2012 08:39
-
-
Save batako/3696949 to your computer and use it in GitHub Desktop.
パス文字列からファイル名/ディレクトリ名/拡張子を抽出する
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
パスを次のように代入していると仮定する | |
PATH="/Users/batako/Download/pantsu.zip" | |
【フルファイル名取得】 | |
echo ${PATH##*/} | |
#出力結果:pantsu.zip | |
【ファイル名のみ取得】 | |
full_filename=${PATH##*/} | |
echo ${full_filename%.*} | |
#出力結果:pantsu | |
【ファイルがある場所のパス取得】 | |
echo ${PATH%/*} | |
#出力結果:/Users/batako/Download | |
※ PATHがファイル名のみの場合ファイル名になる | |
【拡張子】 | |
echo ${PATH##*.} | |
#出力結果:zip |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment