Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store date variable in bash script

Tags:

bash

I want to store date values into a variable for future use. Please correct the sample script:

#!/bin/bash
Now_hourly = $(date +%d-%b-%H_%M)    
Now_daily = $(date +%d-%b-daily)    
echo $(Now_hourly)    
echo $(Now_daily)

The output should be : 12-Feb-17_50 and 12-Feb-daily
But When I run the script, I am getting below error :
Now_hourly: command not found
Now_daily: command not found

like image 347
Gopu Avatar asked Feb 12 '14 07:02

Gopu


1 Answers

you can change the script like:

#!/bin/bash
Now_hourly=$(date +%d-%b-%H_%M)    
Now_daily=$(date +%d-%b-daily)    
echo "$Now_hourly"
echo "$Now_daily"

I think the problem is spaces around =

output:

12-Feb-12_03
12-Feb-daily
like image 186
MLSC Avatar answered Oct 27 '22 16:10

MLSC