ITeye博客

bash操作数组

luogen33 · 2011-09-06 23:31 · 编程语言 · Markdown

#!/bin/bash declare -a colors; echo "Enter your favorite colors (septated from each other by space)."; read -a colors; #get the length of array element_count=${#colors}; index=0;

#all over the array. echo "------all over the array------";

#the No1. method. echo "---the No1. method ----"; while
do echo ${colors}; let "index = $index + 1"; done

#the No2 method. echo "----the No2 method----"; for item in ${colors} do echo $item; done

#remove items of array echo "-----remove items of array-----"; #remove the first item of colors array. unset colors; echo ${#colors}; #remove all items of colors array,there are three methods . #unset colors; unset colors ; #unset colors; echo ${#color};

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。