Shell Script-relational array

Source: Internet
Author: User


  1 ################################## #######################################     2 # file name:  muscian.sh  3 # author: dty  4 # mail: [email protected ]  5 # created time: wed 05 aug 2015 04:41:14 pm  Cst  6 #########################################################################  7  #!/bin/bash  8 declare -a beatles  9 beatles= ( [singer]= John [bassist]=paul [drummer]=ringo [guitarist]=george)  10 for muscian in   singer bassist drummer guitarist 11 do 12      echo  "the ${muscian} is ${beatles[$muscian]}"//Note calls must be added with the $ sign in [] ....  13 done~ 

1 ######################################################################### 2 # File Name:instruments.sh 3 # Author: Dty 4 # Mail: [email protected] 5 # Created time:wed 04:50:45 PM CST 6 ################################## ####################################### 7 #!/bin/bash 8 declare-a Beatles 9 beatles= ([Singer]=john [Bassist]=paul] [Dr  Ummer]=ringo [Guitarist]=george] instrument in ${!beatles[@]}//Direct reverse call is equivalent to printing singer bassist drummer guitarist 11 Do-echo "the ${instrument} is ${beatles[$instrument]}" done~


All two of these programs are expressions of relational arrays.

The first reference, the second backward reference ${!array[@]}, the relational array that uses the value in conjunction with the index must first

Declare-a

To declare


To practice practiced hand a simple, Lee is Chinsese people, Kobe are US people. Dirk is German people

  1 #########################################################################       2 # file name: dirk.sh     3 # author : dty      4 # mail: [email protected]       5 # created time: wed 05 aug 2015 05:02:53  pm cst      6 ################################################## #######################      7 #!/bin/bash       8 declare -a people      9 people= ( [chinese]=lee  [us]=kobe [german]=dirk )      10 for ship in  chinese us german     11 do     12      echo the ${people[$ship]} is   $ship  people     13 done     [[email protected] mnt]# ./dirk.sh     the  lee is chinese people     the kobe is us  People     the dirk is german people

Shell Script-relational array

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.