In the bash shell,
$ date +%Y%m%d%H%M
202208161535
So I put it in a bash script
#!/bin/bash
dat=${date +%Y%m%d%H%M}
echo "dat=" ${dat}
But when I run it, I get
$ test.bash
./test.bash: line 2: ${date +%Y%m%d%H%M}: bad substitution
dat=
How should I do it?
ADD
I found
dat=`date +%Y%m%d%H%M`
works. But I'm curious how I can do it with dat = ${data +%Y%m%d%H%M}
.
ADD2
This question arose because of the mistake, or rather from not knowing the difference of ( ) and { }. Those who cannot notice this difference cannot search with search pattern 'difference of ( ) and { } in bash'. So the referenced links 'supposed to have solution for this question' cannot be searchable by the people like me. So I think this question is worth being kept as is.