zoukankan      html  css  js  c++  java
  • Shell学习——数组

    1、普通数组:只能用整数作为索引
    1.1、赋值
    [root@client02 ~]# array[0]=test1
    [root@client02 ~]# array[1]=test2
    [root@client02 ~]# array[2]=test3
    1.2、打印
    [root@client02 ~]# echo ${array[0]}
    test1
    [root@client02 ~]#
    [root@client02 ~]# echo ${array[*]}
    test1 test2 test3
    [root@client02 ~]# echo ${array[@]}
    test1 test2 test3
    1.3、打印数组长度
    [root@client02 ~]# echo ${#array[*]}
    3
    [root@client02 ~]#
    1.4、列出数组索引
    [root@client02 ~]# echo ${!array[*]}
    0 1 2
    [root@client02 ~]#
    2、关联数组:可以使用任何文本作为索引
    2.1、关联数组定义
    [root@client02 ~]# declare -A fruits_value
    [root@client02 ~]# fruits_value=([apple]='10 yuan' [orange]='8 yuan')
    [root@client02 ~]# echo "Apple costs ${fruits_value[apple]}"
    Apple costs 10 yuan
    [root@client02 ~]# echo ${!fruits_value[*]}
    orange apple
    [root@client02 ~]#

  • 相关阅读:
    大数据面经
    mysql复习(2)
    java容器
    内存管理
    垃圾收集
    输入/输出流
    排序算法的稳定性及其汇总
    java传值与传引用
    linux复习6
    linux复习5
  • 原文地址:https://www.cnblogs.com/pigwan7/p/9629311.html
Copyright © 2011-2022 走看看