test_path="/tmp/test/file.txt"
・ファイル名
echo ${test_path##*/}
⇒ file.txt
解説)
"*/"で表される文字列から最長一致の接頭部を除去する。
・ファイルパス
echo ${test_path%/*}
⇒/tmp/test
"/*"で表される最短一致接尾部を除去する。
サイトマップ