calcola_stagioni.sh

Mar 1st, 2012
317
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. #!/bin/bash
2. #Estraggo mese_giorno "MMDD"
3. mg=`echo \$1 | awk -F "/" '{ print \$2\$1}'`
4. #Estraggo anno "YYYY"
5. y=`echo \$1 | awk -F "/" '{ print \$3}'`
6.
7. #Lista date stagioni
8. begin_year=0101
9. begin_spring=0321
10. begin_summer=0621
11. begin_autumn=0923
12. begin_winter=1221
13. end_year=1231
14.
15. #Lista equinozi e solstizi
16. equ_spring=0321
17. sol_summer=0621
18. equ_autumn=0923
19. sul_winter=1221
20.
21. #Controlla stagione
22. if [ \$mg -ge \$begin_year -a \$mg -lt \$begin_spring ]; then
23.   echo "Inverno"
24. elif [ \$mg -ge \$begin_spring -a \$mg -lt \$begin_summer ]; then
25.   echo "Primavera"
26. elif [ \$mg -ge \$begin_summer -a \$mg -lt \$begin_autumn ]; then
27.   echo "Estate"
28. elif [ \$mg -ge \$begin_autumn -a \$mg -lt \$begin_winter ]; then
29.   echo "Autunno"
30. elif [ \$mg -ge \$begin_winter -a \$mg -lt \$end_year ]; then
31.   echo "Inverno"
32. fi
33.
34. #Controlla solstizi o equinozi
35. if [ \$mg -eq \$equ_spring ]; then
36.   echo "Equinozio di primavera"
37. elif [ \$mg -eq \$sol_summer ]; then
38.   echo "Solstizio d'estate"
39. elif [ \$mg -eq \$begin_summer ]; then
40.   echo "Equinozio d'autunno"
41. elif [ \$mg -eq \$equ_autumn ]; then
42.   echo "Solstizio d'inverno"
43. fi
44.
45. #Controlla anno bisestile
46. if (( (y % 400) == 0 )) || (( (y % 4) == 0 && (y % 100) != 0 )); then
47.   echo "L'anno \$anno e' bisestile"
48. else
49.   echo "L'anno \$anno non e' bisestile"
50. fi