在以下数组中
ARR=(
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "ssssssssssssss"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
)
我需要将值替换ssssssssssssss
为 xxxxxxxxxxxxxx
在以下数组中
ARR=(
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "ssssssssssssss"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
)
我需要将值替换ssssssssssssss
为 xxxxxxxxxxxxxx
使用参数扩展和替换:
ARR=("${ARR[@]/ssssssssssssss/xxxxxxxxxxxxxx}")
Simply assign new value:
ARR[7]="xxxxxxxxxxxxxx"
If you don't know the position of "ssss..." string, you can interate over array:
i=0
for item in ${ARR[*]}
do
if [ "$item" == "ssssssssssssss" ]
then
ARR[$i]="xxxxxxxxxxxxxx"
fi
((i++));
done