i tried the below code to store the date output in variable.
read -p 'date: ' mydate
date_month= date -d "$mydate" +%b
echo $date_month
it is not printing the output. how to store the date output in variable?.
i tried the below code to store the date output in variable.
read -p 'date: ' mydate
date_month= date -d "$mydate" +%b
echo $date_month
it is not printing the output. how to store the date output in variable?.
Your script as written contains
date_month= date -d "$mydate" +%b
Note the space. This runs date -d "$mydate" +%b
with date_month
set to an empty string. In order to put the result of this command in the variable, you have to use command substitution:
date_month=$(date -d "$mydate" +%b)
Note also the lack of a space.