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