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

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -