我想從我的數組中取消設置名稱中有兩個'_'字符的文件夾。但我得到權限被拒絕的錯誤。你能幫我解決嗎?這裏是我的腳本,它的輸出:在shell腳本中使用echo結果如果在一個shell腳本中檢查
#!/bin/sh
ALLVERSION=(/dir/test*)
echo "first version:"
for ((i=0; i<${#ALLVERSION[@]}; i++)); do
if [[ `${ALLVERSION[i]} | grep -o '_' | wc -l` -eq 2 ]]; then
unset ALLVERSION[i]
fi
done
echo "last version:"
for f in "${ALLVERSION[@]}"; do
echo "$f"
done
結果:
first version:
countcharacter.sh: line 6: /dir/test03_01.txt: Permission denied
countcharacter.sh: line 6: /dir/test03_01_01.txt: Permission denied
countcharacter.sh: line 6: /dir/test03_01_04.txt: Permission denied
countcharacter.sh: line 6: /dir/test03_04.txt: Permission denied
countcharacter.sh: line 6: /dir/test03_05_04.txt: Permission denied
countcharacter.sh: line 6: /dir/test04_01_04.txt: Permission denied
countcharacter.sh: line 6: /dir/test05_00.txt: Permission denied
countcharacter.sh: line 6: /dir/test05_01.txt: Permission denied
countcharacter.sh: line 6: /dir/test06_01.txt: Permission denied
last version:
/dir/test03_01.txt
/dir/test03_01_01.txt
/dir/test03_01_04.txt
/dir/test03_04.txt
/dir/test03_05_04.txt
/dir/test04_01_04.txt
/dir/test05_00.txt
/dir/test05_01.txt
/dir/test06_01.txt
如果[['回聲$ {ALLVERSION [I]} | grep -o'_'| wc -l' -eq 2]];那麼 – zzn