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:
- how set variable output command in bash? 12 answers
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
Post a Comment