Concatenating text and command output in Bash script to output to file

只谈情不闲聊 提交于 2019-12-25 01:22:18

问题


I'm writing a bash script in FreeBSD that appends commands to a log file. Before I execute the commands that will append the log data, I want to print a line in the file which shows the current date above the data, like this:

---Tue Aug 20 17:26:37 EDT 2019---

I know that I can use the date command to output the timestamp, but I'm not sure how to include the "---" before and after the timestamp to add to the file. What's the simplest way to do this?


回答1:


You can pass a format string to date:

date '+---%a %b %e %H:%M:%S %Z %Y---'


来源:https://stackoverflow.com/questions/57581745/concatenating-text-and-command-output-in-bash-script-to-output-to-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!