Shell操作数组

#pids=(123 345 678)
pids=$(ps -ef | grep key_word | grep -v grep | grep -v $$ | grep -v `basename $0` | awk '{print $2}')
pid_array=($pids) #ESplit into a array by " "
echo "array is:${pid_array[@]}"  #Print the whole array
echo "array length is:${#pid_array[*]}"  #Print the length of the array
echo ${pid_array[1]}  #Print the second element in the array
pid_array[1]=91011  #Change the second element in the array
echo ${pid_array[1]} #Print the second element in the array again

猜你喜欢

转载自huanyue.iteye.com/blog/1998837