0
我想在一個陣列中的目錄文件名比較字符串和回聲未發現和突破,如果任何一個文件名不存在 - 代碼我寫的是比較在目錄中的文件名數組的字符串
#!/bin/bash
# find all json files recursively; cp to destination folder; try to parameterised/read from a file
#find -name '*.json' -exec cp {} destination_folder/ \;
Dir2="destination_folder/*"
declare -a JSON_MandatoryFiles=('abc.json' 'bcd.json' 'efg.json' 'ijk.json');
for i in $Dir2; do
for j in "${JSON_MandatoryFiles[@]}"; do
if [ $j == $(basename $i) ]; then
echo $j "Found"
break
fi
done
done
然而我無法追蹤我應該在哪裏迴應「未找到」並中斷。請幫助
但是,這給了我沒有發現每次迭代檢查 – RCoder
做一件事..給出目標文件夾的絕對路徑在DIR2爲如。 'DIR2 =「/ home/abc/xyz」'(不要把'/'放在末尾,因爲我們在'if'條件下使用'/' – batMan
@RCoder:我已經更新瞭解決方案!我知道是否有任何問題。 – batMan