我有一個非常微妙的bash的問題:如何限制模式匹配,以第一個匹配的文件
一個目錄內富
$ ls
foo.tgz bar.tgz baz.tgz
我要生成一個bash單排,提取第一個壓縮檔類似的模式:
bash -c "tar -zxvf foo.tgz file1" # fine
bash -c 'tar -zxvf *.tgz file1" # oups trying to extract bar.tgz from foo.tgz!
是否有可能將模式匹配限制爲第一個擴展參數?
細化:
find -iname '*.tgz' | xargs tar -zxvf # oups! cannot add restriction to only extract file1
我比其他人更喜歡這個解決方案,因爲它正確覆蓋沒有找到文件的情況。不幸的是,這兩種解決方案都不會讓它進入代碼,因爲它更容易在代碼中找到文件。 – Alex 2013-02-21 15:39:26