1

Getting the error below as I'm sure my syntax is off somehow with the nested conditionals. Basically I don't want to send an empty message to my telegram_bot which throws an error if it detects empty message. The first IF just detects if its NULL which works. But the case on line 32 doesnt.

xxx.sh: line 32: syntax error near unexpected token `)'
xxx.sh: line 32: `    *)       # contains nothing or only spaces'


 26 if  [ -z "$message" ]; then
 27         echo "Please pipe a message to me!"
 28 else
 29   case $message in
 30     *[!\ ]*) # contains non-space
 31         sendTelegram                                                                                                                                                                                                                      
 32     *)       # contains nothing or only spaces
 33         DO NOTHING...
 34   esac
 35 fi
4

You need to terminate your case clauses:

case $message in
    *[!\ ]*) # contains non-space
        sendTelegram
    ;;                                                                                                                                                                                                          
    *)       # contains nothing or only spaces
        DO NOTHING..
    ;;
esac

Conditional Constructs

Each clause must be terminated with ;;, ;&, or ;;&.

If the ;; operator is used, no subsequent matches are attempted after the first pattern match. Using ;& in place of ;; causes execution to continue with the command-list associated with the next clause, if any. Using ;;& in place of ;; causes the shell to test the patterns in the next clause, if any, and execute any associated command-list on a successful match.


As Kusalananda points out you can actually skip the terminator in the last clause if you so desire.

  • 1
    The ;; is not needed in the last branch. – Kusalananda Feb 22 at 22:32
  • @Kusalananda: TIL. I have always included it though, I don't think it should cause any issues, no? – Jesse_b Feb 22 at 22:33
  • 1
    No, there's nothing wrong with including it. It's just optional at the very end. – Kusalananda Feb 22 at 22:34
  • @ilkkachu POSIX grammar it is. – Kusalananda Feb 22 at 22:50
  • can i just leave my lines 32 and 33 out completely since I just want it to do nothing anyways? – Patoshi パトシ Feb 22 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.