cats *
は cats
関数を呼び出す前に *
がファイル名に展開されます。よって
cats testA.cxx testB.cxx testB.cxx~
と呼び出したことになります。
Like!
bashの関数を作成しているのですが、
その中でlsがうまく機能していないように思われます。
そのような仕様なのか、書き方がまずいのか、ご存知でしたら
お教えいただけませんでしょうか。
bash_profileには以下の関数を定義し、sourceしております。
function cats(){
ls $1
}
これを実行するフォルダの中身は
testA.cxx testB.cxx testB.cxx~
となっています。
通常以下のコマンドを実行すると以下に示すような結果になると思います。
tanukiMac:testArea $ls
testA.cxx testB.cxx testB.cxx~
tanukiMac:testArea $ls *
testA.cxx testB.cxx testB.cxx~
tanukiMac:testArea $ls *cxx
testA.cxx testB.cxx
しかし、今回定義したものを使用すると以下のようになります。
tanukiMac:testArea $cats
testA.cxx testB.cxx testB.cxx~
tanukiMac:testArea $cats *
testA.cxx
tanukiMac:testArea $cats *cxx
testA.cxx
私はlsを使用した時と同様の結果が出ると思っていたのですが、結果は異なりました。
試したこととしては、
function cats(){
echo $1
ls $1
}
上記のようにして、引数に入っているものを確認するようにしました。
その結果は以下のようになり、$1の段階で与えた引数と異なるものになっていることがわかりました。
tanukiMac:testArea $cats
testA.cxx testB.cxx testB.cxx~
tanukiMac:testArea $cats *
testA.cxx
testA.cxx
tanukiMac:testArea $cats *cxx
testA.cxx
testA.cxx
よろしくお願いいたします。
cats *
は cats
関数を呼び出す前に *
がファイル名に展開されます。よって
cats testA.cxx testB.cxx testB.cxx~
と呼び出したことになります。
@tanuki206
Questionerみなさま、
コメントしていただきありがとうございます。
以下のような形で、 $@ を用いれば、複数の変数を与えることが可能であるとわかりました。
function cats(){
ls $@
}
解決いたしましたので、本件はクローズさせていただきます。
ありがとうございました。