I have nothing to worry about. I want to use shell in Linux to write a script for converting the Gregorian calendar to the lunar calendar. It will take about a week to complete. Now let's share it with you.
The principle of this script is the look-up table method (because there is an error in the formula). Based on the lunar new year as the benchmark, two different Chinese calendars before and after the Lunar New Year are calculated.
Before writing this script, you want to add the Gregorian calendar and lunar date to the Linux terminal command prompt. There is Lunar software in Ubuntu to get the Lunar date, but there is no similar software in Fedora or CentOS, so I want to implement one by myself, but I write it in other languages on the Internet, it is unnecessary to write more data. So I want to use shell to write one.
Function: Converts a calendar date to a calendar date.
Time Range: 1901 ~ 2099, the time corresponding to the calendar year is 4598 ~ 4796
Parameter format(If NO parameter is set, the default value is the current system date.): yyyymmdd
For example, February 1, January 1, 2013:
Complete data:
Http://files.cnblogs.com/snowsolf/lunar_20130711.zip
Files in the package:
Lunar. sh main script, specific implementation
Datebases lunar metadata
Change. log change log
Readme script instructions and precautions
The main script lunar. sh code is as follows:
#!/bin/= = ] && DATE=$( +%Y%m%=$( $DATE | =$( $DATE | =$( $DATE | =$( -d $DATE +%=$( /$date_year/!d databases | =$( /$date_year/!d databases | =$( |bc | -e :a -e =$( $lunar_year_data_bin | -e =$( |bc | -e :a -e =$( $lunar_year_data_bin | -e =$( |bc | -e :a -e =$( -d $date_year$new_year_month$new_year_day +%=$( $date_days - $new_year_days + = [ -le ]; ==$(($date_year-=$( /$date_year/!d databases | =$( /$date_year/!d databases | =$( |bc | -e :a -e =$( $lunar_year_data_bin | -e =$( |=$( $lunar_year_data_bin | -e = ] && lunar_month_all_bin=$( $lunar_year_data_bin | -e =$( $lunar_month_all_bin | -e | -e [ = ];== i [ -gt ]; =$(($lunar_day -=$(($lunar_month + ==$((-=$( $lunar_month_all_bin |=$( $lunar_month_all_bin | -e | -e i [ -gt ]; =$(($lunar_day -=$(($lunar_month - =$(($i - [ = ]; $lunar_year-$lunar_month- [ -ge ]; $lunar_year-$lunar_month- [ = ]; [ = ];=$(($lunar_month - $lunar_year-*$lunar_month-=$(($lunar_month - $lunar_year-$lunar_month- $lunar_year-$lunar_month-