In a shell script, there are the following variables:
datestamp=$(date '+%Y-%m-%d_T%H-%M-%S')
datestamp_pretty=$(date '+%m/%d/%Y at %I:%M:%S %p')
The first one is used as part of the output filename while the second one is used to display a nicely readable date and time in the contents of the file. Since these are created separately, the seconds can be off slightly. Is there a way to create a single date variable and then format it two different ways? If so, how is this done?
eval "$(date +"datestamp='%Y-%m-%d_T%H-%M-%S' datestamp_pretty='%m/%d/%Y at %I:%M:%S %p'")"
and avoid relying on that-d
GNU extension. – Stéphane Chazelas Dec 10 '19 at 09:37datestamp_pretty
format of yours is US-specific and would generally not work properly outside a US or C/POSIX locale. Using%c
is probably better for a human-readable date adapted to the user's locale. – Stéphane Chazelas Dec 10 '19 at 09:43%c
be used indatestamp_pretty
to replace the code that's there but yield the same output? – knot22 Dec 11 '19 at 02:42