* ファイルパスの操作 [#z20f94c2]
** 拡張子(またはファイル名の本体)を取り出す [#n7249f2e]
パラメータ展開を使う。パラメータ(file)からパターン(*.または.*)にマッチした箇所の左側(または右側)を取り除く。
:# |パラメータの左側を取り除く。
:% |パラメータの右側を取り除く。
##のように2つ続けると最長一致。
file=1.2.txt
echo ${file##*.} # 拡張子を取り出す
echo ${file#*.}
echo ${file%%.*}
echo ${file%.*} # ファイル名の本体を取り出す
の実行結果↓
txt
2.txt
1
1.2
** フルパスの取得 [#f5015dd0]
find $(pwd) -name foo.txt
=> /home/bar/foo.txt
find $PWD -name foo.txt
readlink -f foo.txt
*** 参考 [#oa7578b7]
http://stackoverflow.com/questions/246215/how-can-i-list-files-with-their-absolute-path-in-linux