Reputation: 213
I am trying to save the current date in the following format to a file and wrap it in a simple json body, so far I was thinking of something like this:
jsonTimeStamp=`$({"timestamp":"$(date +%FT%T.%3N%Z)"})`; > deps/image-details.json
zsh: command not found: timestamp:2020-10-16T10:36:49.3NEDT
this gives me the following error:
command not found: timestamp:2020-10-16T10:38:38.3NEDT
I am out of ideas, can someone please point to what's going wrong here?
Upvotes: 0
Views: 983
Reputation: 247062
You could let date
itself output the JSON:
date '+{"timestamp":"%FT%T.%3N%Z"}'
{"timestamp":"2020-10-16T15:00:11.214EDT"}
Have a close look at what you're doing in your question. I'm going to replace the semicolon with a newline:
jsonTimeStamp=`$({"timestamp":"$(date +%FT%T.%3N%Z)"})`
> deps/image-details.json
You set the variable on the first line, and on the second line you truncate the output file to zero bytes.
Upvotes: 1
Reputation: 19655
jq -cn '{"timestamp":(now|todateiso8601)}' >deps/image-details.json
or
jq -cn '{"timestamp":(now|todate)}' >deps/image-details.json
or
jq -cn '{"timestamp":(now|strftime("%FT%T"))}' >deps/image-details.json
Upvotes: 1