日本高清免费一本视频100禁_在线不卡欧美精品一区二区三区_国产一区二区好的精华液_中文综合在线_国产啊啊啊视频在线观看_大地资源网免费观看高清

IT之道-艾銻知道

您當前位置: 主頁 > IT服務 > 桌面服務 >

Linux系統中 Shell 數組建立及使用技巧


2015-10-12 13:36 作者:admin 瀏覽量:

  1.數組定義

  [chengmo@centos5 ~]$ a=(1 2 3 4 5)

  [chengmo@centos5 ~]$ echo $a

  一對括號表示是數組,數組元素用“空格”符號分割開。(網絡技術外包

  2.數組讀取與賦值

  得到長度:

  [chengmo@centos5 ~]$ echo ${

  #a[@]}

  用${#數組名[@或*]} 可以得到數組長度

  讀?。?/p>

  [chengmo@centos5 ~]$ echo ${a[2]}

  3.[chengmo@centos5 ~]$ echo ${a[*]}

  1 2 3 4 5

  用${數組名[下標]} 下標是從0開始 下標是:*或者@ 得到整個數組內容

  賦值:

  [chengmo@centos5 ~]$ a[1]=100

  [chengmo@centos5 ~]$ echo ${a[*]}

  1 100 3 4 5

  [chengmo@centos5 ~]$ a[5]=100

  [chengmo@centos5 ~]$ echo ${a[*]}

  1 100 3 4 5 100

  直接通過 數組名[下標] 就可以對其進行引用賦值,如果下標不存在,自動添加新一個數組元素

  刪除:

  [chengmo@centos5 ~]$ a=(1 2 3 4 5)

  [chengmo@centos5 ~]$ unset a

  [chengmo@centos5 ~]$ echo ${a[*]}

  [chengmo@centos5 ~]$ a=(1 2 3 4 5)

  [chengmo@centos5 ~]$ unset a[1]

  [chengmo@centos5 ~]$ echo ${a[*]}

  1 3 4 5

  [chengmo@centos5 ~]$ echo ${

  #a[*]}

  4.直接通過:unset 數組[下標] 可以清除相應的元素,不帶下標,清除整個數據。(it外包

  3.特殊使用

  分片:

  [chengmo@centos5 ~]$ a=(1 2 3 4 5)

  [chengmo@centos5 ~]$ echo ${a[@]:0:3}

  1 2 3

  [chengmo@centos5 ~]$ echo ${a[@]:1:4}

  2 3 4 5

  [chengmo@centos5 ~]$ c=(${a[@]:1:4})

  [chengmo@centos5 ~]$ echo ${

  #c[@]}

  4.[chengmo@centos5 ~]$ echo ${c[*]}

  2 3 4 5

  直接通過 ${數組名[@或*]:起始位置:長度} 切片原先數組,返回是字符串,中間用“空格”分開,因此如果加上”()”,將得到切片數組,上面例子:c 就是一個新數據。

  替換:

  [chengmo@centos5 ~]$ a=(1 2 3 4 5)

  [chengmo@centos5 ~]$ echo ${a[@]/3/100}

  1 2 100 4 5

  [chengmo@centos5 ~]$ echo ${a[@]}

  1 2 3 4 5

  [chengmo@centos5 ~]$ a=(${a[@]/3/100})

  [chengmo@centos5 ~]$ echo ${a[@]}

  1 2 100 4 5

  調用方法是:${數組名[@或*]/查找字符/替換字符} 該操作不會改變原先數組內容,如果需要修改,可以看上面例子,重新定義數據。(電腦桌面維護外包)

  艾銻無限是中國領先IT外包服務商,專業為企業提供IT運維外包、電腦維護、網絡維護、網絡布線、辦公設備維護、服務器維護、數據備份恢復、門禁監控、網站建設等多項IT服務外包,服務熱線:400-650-7820 聯系電話:010-62684652 咨詢QQ1548853602 地址:北京市海淀區北京科技會展2號樓16D,用心服務每一天,為企業的發展提升更高的效率,創造更大的價值。

  更多的IT外包信息盡在艾銻無限http://www.maosdadas.net


相關文章

IT外包服務
二維碼 關閉
主站蜘蛛池模板: 新干县| 建湖县| 郯城县| 疏附县| 葵青区| 临西县| 玉树县| 公主岭市| 昌黎县| 宜良县| 武夷山市| 清苑县| 泸定县| 长岭县| 汉中市| 将乐县| 大名县| 霍邱县| 农安县| 龙陵县| 盘山县| 沂南县| 蓝山县| 镇原县| 鲜城| 兴城市| 亳州市| 兰西县| 寻乌县| 池州市| 蛟河市| 新乐市| 马边| 剑川县| 新宁县| 尉氏县| 卢湾区| 德昌县| 呼伦贝尔市| 凤台县| 清涧县|