この実証しbash -x
デバッガを使用して、その上の迅速なデバッグ、
bash -xc 'find -type f -name "*.sh" -exec echo $(basename {}) \;'
++ basename '{}'
+ find -type f -name '*.sh' -exec echo '{}' ';'
./1.sh
./abcd/another_file_1_not_ok.sh
./abcd/another_file_2_not_ok.sh
./abcd/another_file_3_not_ok.sh
そして、ちょうどbasename {}
ための[
例は単なるデモの目的のために、私自身です]
bash -xc 'find -type f -name "*.sh" -exec basename {} \;'
+ find -type f -name '*.sh' -exec basename '{}' ';'
1.sh
another_file_1_not_ok.sh
another_file_2_not_ok.sh
another_file_3_not_ok.sh
最初の例でわかるように、echo $(basename {})
は2つのステップで解決されます。basename {}
は実際のファイル(平文ファイル名を出力する)のbasename
以外は何もないので、echo {}
と解釈されます。だから、それはあなたが
bash -xc 'find -type f -name "*.sh" -exec echo {} \;'
+ find -type f -name '*.sh' -exec echo '{}' ';'
./1.sh
./abcd/another_file_1_not_ok.sh
./abcd/another_file_2_not_ok.sh
./abcd/another_file_3_not_ok.sh