0

code:

if [ $mintemp -ge 15 && $maxtemp -le 28 ]; then echo "nice day"; fi

I already have spaces between [ and $Mintemp , 28 and ]

but the error still happend

Yiling Liu
  • 155
  • 1
  • 5
  • Related: [Multiple logical operators, ((A || B) && C), and “syntax error near unexpected token”](https://unix.stackexchange.com/questions/290146/multiple-logical-operators-a-b-c-and-syntax-error-near-unexpected-t) – steeldriver Apr 16 '19 at 14:18
  • Are you using /bin/bash or /bin/sh? If you're using bash specifically, use `[[ ... ]]` instead of `[ ... ]` and then `&&` is OK. – glenn jackman Apr 16 '19 at 15:02

1 Answers1

2

&& is not a [] argument (since [ is actually a program), it is Bash's operator for running second command if the first one succeeds. So for bash your script looks like:

if ([ $mintemp -ge 15) && ($maxtemp -le 28 ]; then echo "nice day"; fi)

Which is invalid. You can however do it like:

if [ $mintemp -ge 15 ] && [ $maxtemp -le 28 ]; then echo "nice day"; fi