I have the following code:
a="$(date)"
echo $a
I want the result of that echo be $(date), not the actual date.
How to achive that?
I have the following code:
a="$(date)"
echo $a
I want the result of that echo be $(date), not the actual date.
How to achive that?
You can't with double quotes, as the assignment had taken place in the first line. Unless you escape the dollar sign:
$ a="\$(date)"
$ echo "$a"
$(date)
$ eval echo "$a"
Fri 5 Oct 18:53:45 CEST 2018
And with single quotes, you might do these:
$ a='$(date)'
$ echo "$a"
$(date)
$ eval echo "$a"
Fri 5 Oct 16:45:45 CEST 2018
$