脚本内容:
#!/usr/bin/env bash
read -p "请输入日期时间:" dt
y=${dt::4}
m=${dt:4:2}
d=${dt:6:2}
T=${dt:8:6}
t=$(echo $T |sed -r 's/..\B/&:/g')
date -d "${y}${m}${d} ${t}" +"%d/%b/%Y:%T"
执行过程:
[root@prod 09:57:04~]# sh t3.sh
请输入日期时间:20211230234009
30/Dec/2021:23:40:09
[root@prod 09:57:06~]# sh t3.sh
请输入日期时间:20211230
30/Dec/2021:00:00:00
[root@prod 09:57:15~]#