核心语句:
echo `date +"%Y-%m-%d %H:%M:%S"`
说明:
无论是在命令行或者shell脚本中都可以执行 核心语句。
这里特别给出shell脚本中的写法:
#!/bin/bash
# 这句很重要,可以理解为引入环境变量
. /home/oracle/.bash_profile
# 定义current_time 变量,格式化时间
current_time=`date +"%Y-%m-%d %H:%M:%S"`
# $current_time,获取变量值
# 整句含义:打印时间,并将打印结果追加到 /opt/test/time_test.txt 文件
echo $current_time >> /opt/test/time_test.txt
结果:
# Out:
# /opt/test/time_test.txt
2019-03-27 17:17:35
The end.