I would like to modify the value to an element of an array and I don’t know the syntax to do it
for i in `seq 0 8`;
do
if [ ${config[$i]} = "value1" ]
then config[$i] = "value2" #<- This line
fi
done
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Technically, the only thing broken there is the whitespace. Don’t put spaces around your operators in shell syntax:
However, there are lots of other little things you may want to think about. For example, if an element of
configcan contain whitespace, the test can break. Use quotes or the[[test keyword to avoid that.seqis a nonstandard external executable. You’d be better off using the builtin iteration syntax. Furthermore, assuming the iteration happens over all the elements inconfig, you probably just want to do: