-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiter_seasons
executable file
·47 lines (39 loc) · 1.22 KB
/
iter_seasons
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
USAGE="Usage: $(basename ${0}) CMD
Iterate over the months of all seasons. The command given as argument
is executed as the body of a loop over the four seasons.
Several special variables are provided, which are expanded when the
command is run:
- \\\${season}: Abbreviation of season in lower case.
- \\\${SEASON}: Abbreviation of season in upper case.
- {months}: Expanded to the bash expressions like '{03..05}' for MAM.
Example:
\$ $(basename ${0}) echo \\\${season} \\\${SEASON} ({months})
djf DJF (01) (02) (12)
mam MAM (03) (04) (05)
jja JJA (06) (07) (08)
son SON (09) (10) (11)
"
main()
{
[ $# -lt 1 ] && { echo "${USAGE}" >&2; return 1; }
local cmd="${@}"
for season in djf mam jja son
do
local SEASON="${season^^}"
case ${season} in
djf) local range='\{01,02,12\}' ;;
mam) local range='\{03..05\}' ;;
jja) local range='\{06..08\}' ;;
son) local range='\{09..11\}' ;;
esac
eval $(eval echo "${cmd//\{months\}/${range}}")
local stat=${?}
if [ ${stat} -ne 0 ]
then
echo "Abort: Command returned error code ${stat}" >&2
return ${stat}
fi
done
}
main "${@}"