리눅스-달력만들기

kyunhyun94·2021년 12월 20일
0

달력 생성

# Shell Script to Enhance the Calendar to Accept 
# MM, MMM, YYYY using cal command

# check whether arguments are passed or not
if [ $# -eq 0 ]
then

        # if arguments are not passed then display this
        echo "Invalid Arguments"
        
        # exit the program
        exit 
fi 

# if 2 arguments are passed
if [ $# -eq 2 ]    
then

    # if argument 1 is greater than 12 or argument 2 
    # is greater than 2021
    if [ $1 -gt 12 -o $2 -gt 2021 ]
    then
    
        # then display invalid month or year
        echo "invalid Year or month"
        
    # else display calendar of the specified month 
    # and year
    else
        ncal $1 $2    
    fi
    
# if only one argument is passed then
else if [ $# -eq 1 ]
then

    # if argument is greater than 12
    if [  $1 -gt 12 ]
    then
        cal $1 # display calendar of specified year
        
    # else display calendar of specified month
    else
        case $1 in #start switch case
            01) m = jan;;
            02) m = feb;;
            03) m = mar;;
            04) m = apr;;
            05) m = may;;
            06) m = jun;;
            07) m = jul;;
            08) m = aug;;
            09) m = sep;;
            10) m = oct;;
            11) m = nov;;
            12) m = dec;;
        esac # end switch case
        echo \" Calander for $1 Month : \"
        
        # display calendar of specified month using -m
        cal -m $1

    fi
fi
fi
  • 실행
./[파일].sh [월]
  • 결과
    스크린샷 2021-12-20 오후 3 36 13
profile
일하기싫어

0개의 댓글