I have this script:
date_time=`date "+%Y%m%d%H%M%S"`
script_name=`basename "$0"`
echo $date_time, $script_name
sleep 2
echo $date_time, $script_name
exit 1
It shows me this (same time).
20200103114357, clone.sh
20200103114357, clone.sh
I need date and time when I call the variable as command. There are 2 seconds between next time, but time is the same. How can I do that? Thanks.
Your code stores the result of the command in the variable, so it never changes. In order to store the command itself in the variable, you need some subtle changes to the quotation marks used, like this:
Set the date time after the sleep again: