-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormdate
More file actions
executable file
·46 lines (41 loc) · 1.21 KB
/
normdate
File metadata and controls
executable file
·46 lines (41 loc) · 1.21 KB
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
#!/bin/bash
# normdate -- 날짜 지정에서 월 필드를 세 자로 정규화하며, 첫 글자는 대문자다.
# 스크립트 #7의 날짜 검증에 대한 도움 함수다.
# 오류가 없으면 0으로 종료한다.
monthNumToName()
{
# 'month' 변수를 적절한 값으로 설정한다.
case $1 in
1 ) month="Jan" ;; 2 ) month="Feb" ;;
3 ) month="Mar" ;; 4 ) month="Apr" ;;
5 ) month="May" ;; 6 ) month="Jun" ;;
7 ) month="Jul" ;; 8 ) month="Aug" ;;
9 ) month="Sep" ;; 10) month="Oct" ;;
11) month="Nov" ;; 12) month="Dec" ;;
* ) echo "$0: Unknown month value $1" >&2;
exit 1
esac
# 다른 스크립트에서 monthNumToName()을 이용하려면 다음 문장의 주석 해제
# echo $month $2 $3
return 0
}
# 메인 스크립트
# ============
# 입력 유효성 검사
if [ $# -ne 3 ] ; then
echo "Usage: $0 month day year" >&2
echo "Formats are 'August 3 1962' and '8 3 1962'" >&2
exit 1
fi
if [ $3 -le 99 ] ; then
echo "$0: expected 4-digit year value." >&2
exit 1
fi
if [ -z $(echo $1|sed 's/[[:digit:]]//g') ]; then
monthNumToName $1
else
month="$(echo $1|cut -c1|tr '[:lower:]' '[:upper:]')"
month="$month$(echo $1|cut -c2-3 | tr '[:upper:]' '[:lower:]')"
fi
echo $month $2 $3
exit 0