0

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?.

0

1 Answer 1

1

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.

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.