Shell中实现类似于结构体/数组功能的脚本

#!/bin/bash

#ST1, ST2,ST3存放字符串,通过数组下标访问数据

# Struct {

#  STRING A

#  STRING B

#  STRING C

# } Su;

ST1="Quannan Jinlong Mujin Nanjing Longyuanba Bitou"
ST2="Xiancheng Zheng Cun Zheng Zheng Zheng"
ST3="Baishengtai Tianlongshan Wufanghuoku Wenquan Yaxiweiwu Qicheng"

ST1_EXT=($ST1) #转换成数组
ST2_EXT=($ST2)
ST3_EXT=($ST3)


#${#ST1_EXT[@] 计算ST1中的字符串个数

for ((i=0; i<${#ST1_EXT[@]}; i++)); do
    sleep 1
    echo "#### ${ST1_EXT[i]} -> ${ST2_EXT[i]} -> ${ST3_EXT[i]} #####"

done


参考文献:

1. Linux Shell for循环写法总结    http://www.linuxdiyf.com/viewarticle.php?id=206569

2. Shell中的字符串处理                http://blog.chinaunix.net/uid-20476365-id-1942369.html



你可能感兴趣的:(Linux与Unix,shell编程)