0
我正在嘗試編寫一個腳本,該腳本將對選定的文件進行操作。防止在bash腳本中出現globbing
#!/bin/bash
#ytest
lastArgNo=$#
sPattern=${!lastArgNo}
echo "operating on $sPattern"
#do operation on $sPattern
for sFile in $sPattern do
#do something with each file
done
如果我開始這個腳本 參數* .JPG我得到
operating on IMG_1282.JPG
這是發現模式*正在處理.JPG,只有這個文件的最後一個文件。我需要命令行中給出的實際文件模式。提前致謝。
在運行腳本以完全禁用路徑名擴展(但在此情況下請記住在腳本中將其重新打開)之前,將腳本引用至腳本或運行'set -f'。 – 2015-03-03 14:21:42
[Prevent \ *將在bash腳本中展開]的可能重複(http://stackoverflow.com/questions/2470638/prevent-to-be-expanded-in-the-bash-script) – tripleee 2015-03-03 14:38:25
它不是重複的因爲我無法在腳本中設置-o noglob。用引號逃脫並不能解決問題。 – 2015-03-03 15:11:52