#!/bin/bash # # Usage: # FileNameMon.sh nmon # Copyright by http://scriptdemo.blogspot.com if [ $# -ne 1 ]; then sed -n '3,4p' FileNameMon.sh exit fi case $1 in 1) fnarray[0]="m01d05" fnarray[1]="m01d10" fnarray[2]="m01d15" fnarray[3]="m01d20" fnarray[4]="m01d25" fnarray[5]="m01d30" ;; 2) fnarray[0]="m02d04" fnarray[1]="m02d09" fnarray[2]="m02d14" fnarray[3]="m02d19" fnarray[4]="m02d24" fnarray[5]="m03d01" ;; 3) fnarray[0]="m03d06" fnarray[1]="m03d11" fnarray[2]="m03d16" fnarray[3]="m03d21" fnarray[4]="m03d26" fnarray[5]="m03d31" ;; 4) fnarray[0]="m04d05" fnarray[1]="m04d10" fnarray[2]="m04d15" fnarray[3]="m04d20" fnarray[4]="m04d25" fnarray[5]="m04d30" ;; 5) fnarray[0]="m05d05" fnarray[1]="m05d10" fnarray[2]="m05d15" fnarray[3]="m05d20" fnarray[4]="m05d25" fnarray[5]="m05d30" ;; 6) fnarray[0]="m06d04" fnarray[1]="m06d09" fnarray[2]="m06d14" fnarray[3]="m06d19" fnarray[4]="m06d24" fnarray[5]="m06d29" ;; 7) fnarray[0]="m07d04" fnarray[1]="m07d09" fnarray[2]="m07d14" fnarray[3]="m07d19" fnarray[4]="m07d24" fnarray[5]="m07d29" ;; 8) fnarray[0]="m08d03" fnarray[1]="m08d08" fnarray[2]="m08d13" fnarray[3]="m08d18" fnarray[4]="m08d23" fnarray[5]="m08d28" fnarray[6]="m09d02" ;; 9) fnarray[0]="m09d07" fnarray[1]="m09d12" fnarray[2]="m09d17" fnarray[3]="m09d22" fnarray[4]="m09d27" fnarray[5]="m10d02" ;; 10) fnarray[0]="m10d07" fnarray[1]="m10d12" fnarray[2]="m10d17" fnarray[3]="m10d22" fnarray[4]="m10d27" fnarray[5]="m11d01" ;; 11) fnarray[0]="m11d06" fnarray[1]="m11d11" fnarray[2]="m11d16" fnarray[3]="m11d21" fnarray[4]="m11d26" fnarray[5]="m12d01" ;; 12) fnarray[0]="m12d06" fnarray[1]="m12d11" fnarray[2]="m12d16" fnarray[3]="m12d21" fnarray[4]="m12d26" fnarray[5]="m12d31" ;; *) echo "Undefined month: $1" exit ;; esac echo ${fnarray[*]} |
mmddstr=(`FileNameMon.sh $month`) # will return an array with the month-day strings.
To get the array size, rather than the length of an array element, either ${#mmddstr[*]} or ${#mmddstr[@]} works well. One should notice that ${#mmddstr} shows something different but the max length of all the array elements.
No comments:
Post a Comment