有點奇怪的bash script 參數問題 - Linux

Table of Contents

承上,

感謝CP64的解說,所以說萬用字元*會在有參數的script執行中轉譯2次?

接下來就跟萬用字元有關的問題,如下圖:

ls c* 就是列出 c開頭的檔案,所以得到 cccc. command.sss

ls c\* 因為*被 \ escape掉了,所以列出叫 c* 的檔案,但是沒有叫 c* 的檔案,
所以顯示 c*: No such file or directory

find . -name c\* 應該也要顯示 No such file or directory ?
為何可以找到./cccc.
./command.sss

http://i65ynb.2fh.co/pics/wildc.jpg


--

All Comments

Catherine avatarCatherine2015-10-13
因為find也把 '*' 當作 wildcard
Jake avatarJake2015-10-13
find . -name c\* 也有escape呀! 比較 ls c\*
Margaret avatarMargaret2015-10-18
因為 find 最後吃到的還是 c*
Freda avatarFreda2015-10-21
如果你資料夾底下有 ca cb cc 3個檔案
因為它是 find
Olga avatarOlga2015-10-22
為何 ls c\* 就不一樣?
Andy avatarAndy2015-10-24
前面說有那3個檔案時 你執行 ls c* 會被變成 ls ca cb cc
Puput avatarPuput2015-10-26
執行 ls c\* 實際執行的是 ls c*
Lily avatarLily2015-10-29
然後 find 本身會拿 -name 後面拿到的字串做 wildcard 比對
Isla avatarIsla2015-10-30
普遍來說,ls c\* 是特例,還是 find c\*是特例?
Doris avatarDoris2015-11-03
個人觀點是 find c\*
因為不是每隻程式都會把吃進來的*再轉譯一次
Susan avatarSusan2015-11-08
啊 但是 find 只有 -name 後面的參數才會喔
Hazel avatarHazel2015-11-13
真是的,被這些'棉棉角角'弄的頭婚腦帳
Cara avatarCara2015-11-16
如果你不希望 shell 亂解特殊符號的話 記得用 '' 框起來
Christine avatarChristine2015-11-16
都不是特例啊 你寫個程式自己處理argv就知道了
Kelly avatarKelly2015-11-20
哪有什麼特例? man find 看一下 -name 會花很多時間?
不然就 'c\*' 做兩次不會喔
Linda avatarLinda2015-11-22
覺得 bash 預設很難用也可以 GLOBIGNORE 幹掉 *
Ophelia avatarOphelia2015-11-23
用set -x打開 就可以知道真正下到程式裡的argument們了