linux - How do I use a UNIX bash script variable assigned a value from the date command in a conditional statement -


this question has answer here:

i'm new unix coding please kind. trying use date command obtain current month's abbreviated name , store variable. i'm using variable check against in if statement see if equal "jan" should be. echo variable first test value , prints jan. unfortunately, if statement refuses catch variable being equal "jan" though seems though is. have tried using cut command select first 3 characters rule out trailing white spaces or other format issues. ideas why date function not working expected?

here script:

#! /bin/bash  month= date +"%b"  if[[ $month == "jan"]] echo current month, january has 31 days  else echo error retrieving month! fi 

i running terminal on ubuntu virtual machine bash script.

bash can finicky if syntax (e.g. spaces matter). also, needed virgule [or equivalent] syntax:

#! /bin/bash  month=`date +"%b"`  if [[ "$month" == "jan" ]] ;     echo current month, january has 31 days else     echo error retrieving month! fi 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

java - Log4j2 configuration not found when running standalone application builded by shade plugin -

python - How do I create a list index that loops through integers in another list -