当前位置:网站首页>shell 规范日期格式
shell 规范日期格式
2022-06-30 00:40:00 【我的天才女友】
#!/bin/bash
monthNumToName(){
# 这里使用case语句,根据传递过来的第一个参数,设置返回的月份的格式
case $1 in
1 ) month="Jpa" ;;
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 numberic month value $1">&2
exit 1
# shell和别的语言不一样 1 多认为异常 0 代表正常 true
esac
return 0
}
# -ne 参数不等于3个,注意[]和字符相接都有空格
if [ $# -ne 3 ];then
echo "$0: 期待接收 月 日 年">&2
echo "格式是 August 3 1963 and 8 3 1962">&2
exit 1
fi
# 判断年的参数必须为4为数字
if [ $3 -le 999 ]; then
echo "$0: 年必须是4位数字">&2
exit 1
fi
# -z 判断是否不为空,为空返回true,set过滤出不是数字的字符,如果为空那么就可以进行月份匹配
if [ -z $(echo $1 | set '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
边栏推荐
- MySQL基础2
- 面试官:大量请求 Redis 不存在的数据,从而影响数据库,该如何解决?
- 玉米地里的小鸟
- How to create a module in the idea and how to delete a module in the idea?
- [qnx hypervisor 2.2 user manual]6.2.2 communication between guest and host
- HDCP Paring
- What is the essential difference between get and post requests?
- YuMinHong: my retreat and advance; The five best software architecture patterns that architects must understand; Redis kills 52 consecutive questions | manong weekly VIP member exclusive email weekly
- 【Spark】scala基础操作(持续更新)
- modbus-tcp-rtu协议图表
猜你喜欢

Use of shortcut keys for idea tools

数据中台咋就从“小甜甜”变成了“牛夫人”?

【mysql篇-基础篇】通用语法2

Botu V16 changes the model and firmware version of PLC

Mr. Hu Bo, CIO of weiduomei, a scientific innovator: digitalization is a bloodless revolution, and the correct answer lies in the field of business

外包干了三年,废的一踏糊涂...

MySQL deadlock

The SQL statement concat cannot find the result

Outsourcing for 3 years is a waste

月薪没到30K的程序员必须要背的面试八股,我先啃为敬!
随机推荐
Byte, word, doubleword relationship
间歇采样转发干扰
Top performance version 2 reading notes (IV) -- memory monitoring
一些生活的思考
Arlo felt lost
leetcode 416. Partition equal subset sum partition equal subset sum (medium)
【UML】UML的几种关系(依赖-关联-聚合-组合-继承-实现)
阿洛觉得自己迷茫
如何做好测试用例设计
[MySQL basic] general syntax 2
【PHP】php压测,报错:通常每个套接字地址(协议/网络地址/端口)只允许使用
博途V16 更改PLC的型号和固件版本
【每日一题】二叉树的前后序遍历
太卷了~ 八股文,面试最强王者!
[programming problem] maze problem
MySQL foundation 3
About SQL: create a view_ XB view, whose function is ① to delete views with duplicate names before creating them ② to display the number of male and female students in this class in the XSB table, and
Outsourcing for 3 years is a waste
Use of shortcut keys for idea tools
Ml: introduction to confidence interval (the difference and relationship between precision / accuracy / accuracy), use method, and detailed introduction to case application