shell - linux 下sh文件 的 时间输出
迷茫
迷茫 2017-04-17 13:29:54
0
3
807

在linux 编辑 sh文件

filename=`date +%Y%m%d`

目前只有日期 而没有当天的时间

请问 在后面加上时间 怎么变小呢

filename=`date +%Y%m%d%H`

在这里加上 %H

就会报错 !、

求sh文件编辑 高手 指导一下

filename=`date +%Y%m%d %H:%M:%S`

报错信息如下

date: extra operand ‘%H:%M:%S’
Try 'date --help' for more information.
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(3)
Peter_Zhu

You need to escape the spaces, or make a slight change, wrap the entire formatting parameters in single quotes, and add variable references on the outer layer, so it doesn’t matter how many spaces you put in the middle. The code is as follows

shellfilename=$(date '+%Y%m%d %H:%M:%S')
echo $filename
PHPzhong

filename=date +%Y%m%d%H
Will this cause an error? What system are you using? I tried it in my centos virtual machine and it worked fine. As for filename=date +%Y%m%d %H:%M:%S, change it to filename=date +%Y%m%d %H:%M:%S; then

左手右手慢动作

Escape spaces or pass '%H:%M:%S' as the second parameter

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template