Error in Bash Script Nested Conditional Statements












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









share|improve this question



























    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









    share|improve this question

























      1












      1








      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









      share|improve this question














      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






      bash shell-script scripting






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 22 at 22:23









      Patoshi パトシPatoshi パトシ

      56341322




      56341322






















          1 Answer
          1






          active

          oldest

          votes


















          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.






          share|improve this answer





















          • 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








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502411%2ferror-in-bash-script-nested-conditional-statements%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          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.






          share|improve this answer





















          • 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
















          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.






          share|improve this answer





















          • 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














          4












          4








          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.






          share|improve this answer















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 22 at 22:36

























          answered Feb 22 at 22:27









          Jesse_bJesse_b

          13.3k23370




          13.3k23370








          • 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














          • 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








          1




          1





          The ;; is not needed in the last branch.

          – Kusalananda
          Feb 22 at 22:32





          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





          @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




          1





          No, there's nothing wrong with including it. It's just optional at the very end.

          – Kusalananda
          Feb 22 at 22:34







          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





          @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





          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


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f502411%2ferror-in-bash-script-nested-conditional-statements%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

          is 'sed' thread safe

          How to make a Squid Proxy server?