Abr*_*kjl 1 unix bash shell scripting date
我的问题是尝试使用cut -c选项只从日期命令中减少时间现在我有这个:
today=$(date)
echo The date right now is "$today"
echo The time right now is cut -c 11-18 $today
Run Code Online (Sandbox Code Playgroud)
它现在无法完全读取它,我只想要时间
当前输出:
现在的日期是2017年4月26日星期四18:46:59
现在的时间是
嗯,这样做的行就像是(考虑到这cut是基于一个,所以你想要的第一个字符位置是12而不是11):
echo "The time right now is $(echo "${today}" | cut -c 12-19)"
Run Code Online (Sandbox Code Playgroud)
但绝对没有必要诉诸cut.变量扩展bash将通过子串提取完成此操作(从零开始,因此在位置11处有8个字符):
echo "The time right now is ${today:11:8}"
Run Code Online (Sandbox Code Playgroud)