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 ~]#

  • 相关阅读:
    HTML页引用CSS
    C#反射
    Marshal.SecureStringToBSTR
    SQL语句创建表和数据库
    抽象类和抽象方法
    3 Sum Closest
    Chapter 2: Binary Search & Sorted Array
    Spiral Matrix
    Pascal's Triangle
    Plus One
  • 原文地址:https://www.cnblogs.com/pigwan7/p/9629311.html
Copyright © 2011-2022 走看看