1

在以下数组中

ARR=(
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "ssssssssssssss"
"xxx" "xxxxxxxxxxxxxx"
"xxx" "xxxxxxxxxxxxxx"
)

我需要将值替换ssssssssssssssxxxxxxxxxxxxxx

4

2 回答 2

5

使用参数扩展和替换:

ARR=("${ARR[@]/ssssssssssssss/xxxxxxxxxxxxxx}")
于 2013-03-05T12:26:48.053 回答
0

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
于 2013-03-05T12:13:40.647 回答