I have an array with different values, and if the value is 3 (integer) this value will be exchanged for 999 (integer). But I have a syntax problem in the 'if' block of the array.
The correct return would be: 1 999 5 7 9 999
vetor=(1 3 5 7 9 3)
for i in ${vetor[*]}
do
if [[ ${vetor[i]} = 3 ]]; then
${vetor[i]} = 999
fi
echo $i
done
vetor[i]=999there are no spaces surrounding'='when used for assignment. You do not use$(dereference) when making assignment. Also understand[[ ${vetor[i]} = 3 ]]makes a string comparison, while[[ ${vetor[i]} -eq 3 ]]makes a numeric comparison. Changingvetor[i]does not change the loop variablei.