Evaluate Variable At Runtime

Hi,

I am trying to set a variable that has time the format desired. And my intention is to echo variable (instead of actual date command) everytime I like to echo date. Please take a look at below code.

 
$NOW='['$(date +"%Y-%d-%m %r")']'
echo $NOW
[2013-22-07 04:09:36 AM]

After 5 minutes

$echo $NOW
[2013-22-07 04:09:36 AM]

Issue here is , I am not able to figure out how to evaluate NOW varialbe at run time. It keeps displaying the same time.
I tried some combinations with expr , eval and " ` " , but none of them work.

Can you please help me here.

looking at your req i suggest you using

or else it should be

vidya> v=date
vidya> echo `$v`
Mon Jul 22 12:00:44 CEST 2013
vidya> echo `$v`
Mon Jul 22 12:00:48 CEST 2013
vidya> echo `$v`
Mon Jul 22 12:00:50 CEST 2013
vidya>
 
1 Like
$ alias NOW='echo [$(date +"%Y-%d-%m %r")]'
$ NOW
[2013-22-07 3:31:05 PM]
$ NOW
[2013-22-07 3:31:07 PM]
1 Like