当前位置:网站首页>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
边栏推荐
- TwinCAT 3 EL7211模塊控制倍福伺服
- C语言课设心得之“推箱子”课设作品开源分享
- MySQL基础2
- MySQL高级篇1
- [uitableview] Pit 1: tableview:heightforheaderinsection: method does not execute
- 干外包3年,真废了...
- Database learning notes (sql03)
- [graduation season 𞓜 advanced technology Er] employees who have worked for seven years do not want you to take another detour
- [garment software] what are the criteria for the selection of garment production management system?
- [mrctf2020]ezpop-1 | PHP serialization
猜你喜欢

TwinCAT 3 EL7211模块控制倍福伺服

HDCP Paring

MySQL advanced 1

Top performance version 2 reading notes (IV) -- memory monitoring

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

Interviewer: why does database connection consume resources? I can't even answer.. I was stunned!

Serpentine matrix (array simulates direction, D represents turning)

网络方向哪个发展更好?数据通信工程师学习路线分享

解决choice金融终端Excel/Wps插件修复visual basic异常

How to create a module in the idea and how to delete a module in the idea?
随机推荐
字节面试惨遭滑铁卢:一面就被吊打,幸得华为内推,三面拿到offer
Initial i/o and its basic operations
The third bullet of wechat payment app application for refund
A Si's mood swings
数据库学习笔记(SQL03)
Ml: introduction to confidence interval (the difference and relationship between precision / accuracy / accuracy), use method, and detailed introduction to case application
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
Move DataGridView up and down
MySQL deadlock
如何在IDEA中自定义模板、快速生成完整的代码?
Serpentine matrix (array simulates direction, D represents turning)
降低打新的预期
PHP wechat merchant transfer to change initiating merchant transfer API
解决choice金融终端Excel/Wps插件修复visual basic异常
Le module twincat 3 el7211 contrôle les servocommandes baffle
Byte, word, doubleword relationship
阿于的彩虹桥
Interviewer: how to solve the problem of massive requests for data that does not exist in redis, which affects the database?
Some thoughts on life
数据中台咋就从“小甜甜”变成了“牛夫人”?