![](/img/trans.png)
[英]" ']' expected " error when assigning a value to an element of a 2d array
[英]operand expected (error token is “+ ”): Bash error when adding array element value to numerical variable
我一直在研究bash腳本,以生成用於在其他(輔助)服務器上復制數據庫的腳本。
輔助主機上有6個存儲文件的位置(因此for循環0 >= i >=5
)。
該腳本的主要目的是檢查輔助主機的位置是否具有足夠的空間來容納將要復制到其中的文件。
aux_dest_space
是輔助主機上已安裝位置上的可用空間; 文件的存儲位置(數組)。 temp_space
是文件大小(累積); 為了在aux_dest_space已滿時停止復制過程。 df_size
是文件大小(存儲在數組中) 錯誤信息:
./script.sh: line 108: 472879112 + : syntax error: operand expected (error token is "+ ")
temp_space=$(( $temp_space + ${df_size[${k}]} ))
我的代碼:
for (( i=0; i<=5; i++ ))
do
while [ ${aux_dest_space[${i}]} -gt $temp_space ]
do
.
.
.
.
k=$((k+1))
temp_space=$(( $temp_space + ${df_size[${k}]} )) # (line 108 - error)
done
temp_space=${df_size[${k}]}
done
在循環之前將$temp_space
初始化為零:
temp_space=0
for (( i=0; i<=5; i++ ))
do
while [ ${aux_dest_space[${i}]} -gt $temp_space ]
do
.
.
.
.
k=$((k+1))
temp_space=$(( $temp_space + ${df_size[${k}]} )) # (line 108 - error)
done
temp_space=${df_size[${k}]}
done
temp_space=0
for (( i=0; i<=5; i++ ))
do
while [ ${aux_dest_space[${i}]} -gt $temp_space ]
do
.
.
.
.
k=$((k+1))
temp_space=$(( temp_space + df_size[${k}] )) # (line 108 - error)
done
temp_space=${df_size[${k}]}
done
我必須從第108行中刪除美元符號和大括號; 這給了錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.