vendredi 21 mai 2021

'if' in array w/ Shell Script

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

Aucun commentaire:

Enregistrer un commentaire