Error in Bash Script Nested Conditional Statements
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
add a comment |
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
add a comment |
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
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
bash shell-script scripting
asked Feb 22 at 22:23
Patoshi パトシPatoshi パトシ
56341322
56341322
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
|
show 1 more comment
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
|
show 1 more comment
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
|
show 1 more comment
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.
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.
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
|
show 1 more comment
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
|
show 1 more comment
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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