嘗試的腳本,要找出folder_list 比file_list 多的元素,并且用一個數組保存起來#check if there are any files addedt=0for m in "${folder_list[@]}"dofor l in "${file_list[@]}"doif [ "$m" == "$l" ]; thenunset $folder_list[$m]fidonedone
1 回答

絕地無雙
TA貢獻1946條經驗 獲得超4個贊
unset 不能這么用,需要指定數組索引,也就是數組下標,而不是數組的值,你可以這樣干:
#check if there are any files added
folder_list=(1 2 3 4 5)
file_list=(1 2)
declare -a result_list
t=0
flag=0
echo folder_list=${folder_list[*]}
echo file_list=${file_list[*]}
for m in "${folder_list[@]}"
do
for l in "${file_list[@]}"
do
if [ "$m" == "$l" ]; then
flag=1
break
fi
done
if [ $flag -eq 0 ]; then
result_list[t]=$m
t=$((t+1))
else
flag=0
fi
done
echo result_list=${result_list[*]}
弄個結果數組保存結果,把在file_list里找不到的folder_list值存到結果數組中。
- 1 回答
- 0 關注
- 1853 瀏覽
添加回答
舉報
0/150
提交
取消