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

  • 相关阅读:
    Navicat12激活,最新版本v12.1.18,原版激活[windows]
    【工具】Fiddler使用教程
    MongoDB笔记
    MongoDB
    MySQL三层结构、用户权限、索引设计原则
    Ajax
    linux简单优化
    linux基本
    Memcached
    Django+Uwsgi+Nginx
  • 原文地址:https://www.cnblogs.com/pigwan7/p/9629311.html
Copyright © 2011-2022 走看看