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