I want to make the date
command with nice formatting like this:
$ date +"%Y-%m-%d %H:%M:%S"
2015-09-17 16:51:58
But I want to save this in variable, so I could call from script like this:
echo "$(nice_date) [WARNING] etc etc"
However it does not work
$ nice_date="date +%Y-%m-%d %H:%M:%S"
$ echo "$($nice_date)"
date: extra operand ‘%H:%M:%S’
Try 'date --help' for more information.
$ nice_date="date +\"%Y-%m-%d %H:%M:%S\""
$ echo "$($nice_date)"
date: extra operand ‘%H:%M:%S"’
Try 'date --help' for more information.
$ nice_date='date +"%Y-%m-%d %H:%M:%S"'
$ echo "$($nice_date)"
date: extra operand ‘%H:%M:%S"’
Try 'date --help' for more information.
What is correct way to do this, so that date command to get one correct argument?
"%F %T"
if you are using GNUdate
. – jordanm Sep 17 '15 at 14:14nice_date="date +%Y-%m-%d-%H:%M:%S"
, it works. I can't currently see how to get that space protected from the second shell. – MadHatter Sep 17 '15 at 14:20