我写了这个显然没有问题的脚本:
#!/bin/bash
DATA=/home/badouble/STORE/rawData_v1r0
LOGS=/home/badouble/bABaReC/CDAS_Selection_log
for dir in $DATA/*/
do
dir=${dir%*/}
echo $dir
ARR=$(echo $dir | tr "/" " ")
echo ${ARR[1]}
done
但它不会产生所需的输出,如下所示:
/home/badouble/STORE/rawData_v1r0/2011-12
/home/badouble/STORE/rawData_v1r0/2012-01
/home/badouble/STORE/rawData_v1r0/2012-02
/home/badouble/STORE/rawData_v1r0/2012-03
/home/badouble/STORE/rawData_v1r0/2012-04
/home/badouble/STORE/rawData_v1r0/2012-05
/home/badouble/STORE/rawData_v1r0/2012-06
/home/badouble/STORE/rawData_v1r0/2012-07
/home/badouble/STORE/rawData_v1r0/2012-08
/home/badouble/STORE/rawData_v1r0/2012-09
/home/badouble/STORE/rawData_v1r0/2012-10
/home/badouble/STORE/rawData_v1r0/2012-11
/home/badouble/STORE/rawData_v1r0/2012-12
/home/badouble/STORE/rawData_v1r0/2013-01
/home/badouble/STORE/rawData_v1r0/2013-02
/home/badouble/STORE/rawData_v1r0/2013-03
它应该打印数组 $ARR 的第二个元素,而不是空白行。
为什么不呢?