Comparing date inside if command in SHELL

With var='date +%d' you're essentialy assigning the string date +%d to $var.

What you probably wanted to do instead, is assign the result of date +%d to $var via command substitution:

var=$(date +%d)
if [ $var = 17 ]
then echo yes
else echo no
fi

Three issues:

  1. You aren't accessing the variable correctly - you need a $ prefix;
  2. You are using single quotes not backticks, when assigning var with the return value of the command;
  3. You are comparing strings (=), not integers (-eq).
var=`date +%d`
if [ $var -eq 17 ]
then echo yes
else echo no
fi