简体   繁体   中英

i can not compare two expressions in Bash

I'm trying to write an expression like this one ---> if [ $condition1 ] && [ $condition2 ] in bash but i keep getting the same error all the times

syntax error near unexpected token `elif'
./leer.sh: line 25: `elif [[ "$($(date +%Y) -eq $ano)"  && "$($(date +%m) -lt $mes)" ]]'

That part of the code is:

elif [[ $($(date +%Y) -eq $year)  && $($(date +%m) -lt $month) ]]
then
echo "Well done";

There are a couple of thing wrong here:

  • your condition does not start with if but with elif
  • you are missing the final fi
  • You try to execute the logical expression using a second $(...)

Do you try to do this?

#!/bin/bash

year=2013
month=11

if [[ $(date +%Y) -eq $year && $(date +%m) -lt $month ]]; then
  echo "Well done"
fi

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM