This is my code:
# Generate Datetime
FILENAME="date +%Y%m%d%H%M%S"
# Dump Database
dumpdb FILENAME
# Upload to S3
python uploaddb.py FILENAME
My worry is that I want to keep referring to “FILENAME” variable except every second the variable will change its value. How can I set the value of FILENAME to the current datetime and then keep it at that same value for the reminder of the script, so that FILENAME always refers to the same value.
To get the output of the
datecommand in the variable value, write:FILENAME="$(date +%Y%m%d%H%M%S)"$FILENAME, not justFILENAME.FILENAME="$(date +%Y%m%d%H%M%S)". It is not re-evaluated each time you reference$FILENAME.