1

I want to make scripts that shows Western Zodiac which accepts as input a person's birthday on the command line and prints out the following:

The day of the week on which the person was born Their Western zodiac sign (cancer, leo, libra, etc.) Their Chinese zodiac sign (wood rabbit, metal snake, fire pig, etc.) Their horoscope (use the Linux fortune cookie program for this)

anyone ever made this ?

0

Find the day of the week by using the format option of the date command:

#!/bin/sh
date -d"${1:mm/dd/yyyy}" +"%A"

Determine the Chinese Zodiac by looking up the year in a table, like this:

#!/bin/sh    
awk -v year="${1:?Year}" '
    $0 ~ year {
        print $1
        found = 1
        exit
    }
    END {
        if (!found)
            exit 1
    }
' <<EOF
    Rat 1912 1924 1936 1948 1960 1972 1984 1996 2008 2020
    Ox 1913 1925 1937 1949 1961 1973 1985 1997 2009 2021
    Tiger 1914 1926 1938 1950 1962 1974 1986 1998 2010 2022
    Rabbit 1915 1927 1939 1951 1963 1975 1987 1999 2011 2023
    Dragon 1916 1928 1940 1952 1964 1976 1988 2000 2012 2024
    Snake 1917 1929 1941 1953 1965 1977 1989 2001 2013 2025
    Horse 1918 1930 1942 1954 1966 1978 1990 2002 2014 2026
    Goat 1919 1931 1943 1955 1967 1979 1991 2003 2015 2027
    Monkey 1920 1932 1944 1956 1968 1980 1992 2004 2016 2028
    Rooster 1921 1933 1945 1957 1969 1981 1993 2005 2017 2029
    Dog 1922 1934 1946 1958 1970 1982 1994 2006 2018 2030
    Pig 1923 1935 1947 1959 1971 1983 1995 2007 2019 2031
EOF

To determine the Western Zodiac requires determining if the birthday is within a range of time. This requires some logic. Again we'll need a table of some sort.

#!/bin/sh
awk --assign M="${1:?Month}" --assign D="${2:?Day}" '
    M == $1 && D >= $2  || M == $3 && D <= $4 {
        print $5
        found = 1
        exit
    }
    END {
        if (!found) {
            exit 1
        }
    }
' <<EOF
    3   21  4   19  Aries
    4   20  5   20  Taurus
    5   21  6   20  Gemini
    6   21  7   22  Cancer
    7   23  8   22  Leo
    8   23  9   22  Virgo
    9   23  10  22  Libra
    10  23  11  21  Scorpio
    11  22  12  21  Sagittarius
    12  22  1   19  Capricorn
    1   20  2   18  Aquarius
    2   19  3   20  Pisces
EOF
  • Siavosh Any feedback? I think it works well, try them out and let me know. – RobertL Nov 8 '15 at 6:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.