Think before you speak, read before you think.

shell数组使用

by

in

shell数组的定义可以通过如下方式
(1) array=(var1 var2 var3 … varN) 直接写每个元素的value
(2) array=([0]=var1 [1]=var2 [2]=var3 … [n]=varN) 写形式[下标]=value
(3) 对每一个变量分开定义
array[0]=var1
arrya[1]=var2

array[n]=varN

可以发现shell数组下标是确定的,有一个备份实践一下array的使用

#!/bin/bash

arrayip=(
[0]=192.168.1.15
[1]=192.168.1.16
)

arraypath=(
[0]=/home/www/bbs
[1]=/home/www/user
)

i=0

while [ “$i” -lt “${#arrayproject[@]}” ] ; do
rsync -a root@${arrayip[$i]}:${arraypath[$i]} /backup/
i=`expr $i + 1`
done


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *