日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

linux shell 數組的長度計算、修改、循環輸出等

系統 2183 0

From :http://blog.csdn.net/snrqtdhuqf/article/details/7242309?

在shell中,數組變量的賦值有兩種方法:

(1) name = (value1 ... valuen)此時下標從0開始

(2) name[index] = value

?example:

  1. #!/bin/sh??
  2. #arrayTest??
  3. name=(yunix?yhx?yfj)??
  4. echo?"array?is:${name[@]}"??
  5. echo?"array?length?is:${#name[*]}"??
  6. echo?${name[1]}??
  7. name[1]=yang??
  8. echo?${name[1]}??
  9. read?-a?name??
  10. echo?${name[1]}??
  11. echo?"loop?the?array"??
  12. len=${#name[*]}??
  13. i=0??
  14. while?[?$i?-lt?$len?]??
  15. do??
  16. echo?${name[$i]}??
  17. let?i++??
  18. done??

result:

array is:yunix yhx yfj
array length is:3
yhx
yang
a b c d e
b
loop the array
a
b
c
d
e

?

下面的是關于數組的輸出實例

example:

?

#!/bin/sh ?

  1. #arrayLoopOut??
  2. read?-a?array??
  3. len=${#array[*]}??
  4. echo?"array's?length?is?$len"??
  5. echo?"use?while?out?the?array:"??
  6. i=0??
  7. while?[?$i?-lt?$len?]??
  8. do??
  9. ????????echo?-n?"${array[$i]}"??
  10. let?i++??
  11. done??
  12. echo??
  13. echo?"use?for?out?the?array:"??
  14. for?((j=0;j<"$len";j=j+1))??
  15. do??
  16. ????????echo?-n?${array[$j]}??
  17. done??
  18. echo??
  19. echo?"use?for?in?out?the?array:"??
  20. for?value?in?${array[*]}??
  21. do??
  22. echo?-n?$value??
  23. done??

result:

a b c d e f g
array's length is 7
use while out the array:
abcdefg
use for out the array:
abcdefg
use for in out the array:
abcdefg

linux shell 數組的長度計算、修改、循環輸出等操作


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 高州市| 喀什市| 襄樊市| 彰武县| 三门县| 马山县| 久治县| 天峻县| 太康县| 阿坝| 仪征市| 吕梁市| 龙川县| 武宣县| 邯郸县| 阳朔县| 东乌珠穆沁旗| 玉环县| 都江堰市| 东方市| 忻州市| 庆元县| 城口县| 元氏县| 武冈市| 凭祥市| 肇庆市| 明光市| 安化县| 遵义市| 建始县| 化德县| 琼中| 新津县| 连江县| 宁武县| 嘉鱼县| 临城县| 昭平县| 宜春市| 繁峙县|