问题
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