【发布时间】:2015-10-24 21:10:08
【问题描述】:
#!/bin/bash
year="${1:0:4}";month="${1:4:2}";day="${1:6:2}"
element=('Wood' 'Fire' 'Earth' 'Metal' 'Water')
rat=(05021924 23021925 24011936 10021937 10021948 28011949 28011960 14021961 15021972 02021973 02021984 19021985 19021996 06021997 07022008 25012009 25012020 11022021 11022032 30012033)
pig=(04021935 23011936 22011947 09021948 08021959 27011960 27011971 14021972 13021983 01021984 31011995 18021996 18022007 06022008 05022019 24012020 23012031 10022032 10022043 29012044)
Scounter=0
Ecounter=1
for (( i=0; i<10; i++ )) #10 is the number of date RANGES
do
echo $i
#done
#echo "start of year"
#Make sure that the base value for Month and Day is base 10 and not base 8. Base 8 is a number starting with 0.
sDay=${rat[$Scounter]:0:2};sMonth=${rat[$Scounter]:2:2};sYear=${rat[$Scounter]:4:4}
#echo "end of year"
eDay=${rat[$Ecounter]:0:2};eMonth=${rat[$Ecounter]:2:2};eYear=${rat[$Ecounter]:4:4}
#10base conversion
#month=$((10#$month))
#day=$((10#$day))
#sMonth=$((10#$sMonth))
#sDay=$((10#$sDay))
#eMonth=$((10#$eMonth))
#eDay=$((10#$eDay))
if [[ $year -eq $sYear && $month -ge $sMonth && $day -ge $sDay || $year -eq $eYear && $month -le $eMonth && $day -le $eDay ]]
then
if [[ $i -gt 4 ]]
then
echo "${element[$((i-5))]} rat"
else
echo "${element[$i]} rat"
fi
fi
Scounter=$((Scounter+2))
Ecounter=$((Ecounter+2))
done
我正在尝试替换 sDay、sMonth、sYear 等中的“老鼠”。带有一个指向数组 rat 或 pig 的变量。我尝试通过放置来使用替换
sDay=${$rat[$Scounter]:0:2};
但我得到一个替换错误
顺便说一句,我正在写一个生肖脚本。
【问题讨论】: