From 3df60d19ecec05df1fa92f871e738fe6bb85e91a Mon Sep 17 00:00:00 2001 From: ZhuangZhu-74 <49544524+ZhuangZhu-74@users.noreply.github.com> Date: Sun, 19 May 2019 10:13:25 +0800 Subject: [PATCH] Update date.md (#107) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为date命令添加用法 --- command/date.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/command/date.md b/command/date.md index 27b7e5d9b3..a182904c6c 100644 --- a/command/date.md +++ b/command/date.md @@ -152,5 +152,19 @@ difference=$(( end - start )) echo $difference seconds. ``` +当你考虑输出带有时间的字符串时,例如(Current time: 2019/05/19): + +最常用的方法: + +```shell +echo -e "Current time: $(date +"%Y%m%d")" +``` + +另一种方法: +```shell +suffix='Current time:' +#和echo的用法差不多,注意如果换成单引号就不能替换变量了。 +date +"${suffix} %Y/%m/%d" +```