Linux:basenameコマンドで複数の引数を処理する方法

スポンサーリンク

basenameコマンドで複数の引数を処理する方法

basenameコマンドで複数の引数を処理するには-aオプションを指定します。

 

オプションの説明

  -a, --multiple support multiple       arguments and treat each as a NAME

 

-aオプションを指定した場合

$ basename -a dir/test1.txt test2.txt
test1.txt
test2.txt

$ basename -a dir/test1.txt test2.txt test3.txt
test1.txt
test2.txt
test3.txt

 

-aオプションを指定しない場合(2番目の引数は拡張子削除の引数として処理される)

$ basename dir/test1.txt test2.txt
test1.txt

$ basename dir/test1.txt .txt
test1

$ basename dir/test1.txt test2.txt test3.txt
basename: extra operand ‘test3.txt’
Try 'basename --help' for more information.