how to use “joker” or wildcard in string patterns (spaces separated words) in a bash case statement?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite
1












How to use bash's "case" statement for "very specific" string patterns (multiple words, including spaces) ?



The problem is: I receive a multi-word String from a function which is pretty specific, including a version number. The version number now changes from time to time. Instead of adding more and more specific string patterns to my case statement, I would like to use a joker (or whatever the word for this is, like "Ubuntu 16.04.? LTS" or "Ubuntu 16.04.* LTS" . However, I didn't find any solution to this yet.



See this shell script I used so far:



 .
.
.
case "$OS" in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
"Ubuntu 16.04.3 LTS" | "Ubuntu 16.04.4 LTS" )
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;
.
.
.






share|improve this question






















  • PS: i read the "pattern" part of the manual and tested some variations of "jokers", but it always failed, since i just forgot to simply drop the doublequotes and to escape the whitespaces. duh!
    – Axel Werner
    Apr 3 at 14:17






  • 1




    I think the term you might be thinking of is "wildcard" (for joker)
    – Jeff Schaller
    Jul 1 at 13:36














up vote
2
down vote

favorite
1












How to use bash's "case" statement for "very specific" string patterns (multiple words, including spaces) ?



The problem is: I receive a multi-word String from a function which is pretty specific, including a version number. The version number now changes from time to time. Instead of adding more and more specific string patterns to my case statement, I would like to use a joker (or whatever the word for this is, like "Ubuntu 16.04.? LTS" or "Ubuntu 16.04.* LTS" . However, I didn't find any solution to this yet.



See this shell script I used so far:



 .
.
.
case "$OS" in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
"Ubuntu 16.04.3 LTS" | "Ubuntu 16.04.4 LTS" )
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;
.
.
.






share|improve this question






















  • PS: i read the "pattern" part of the manual and tested some variations of "jokers", but it always failed, since i just forgot to simply drop the doublequotes and to escape the whitespaces. duh!
    – Axel Werner
    Apr 3 at 14:17






  • 1




    I think the term you might be thinking of is "wildcard" (for joker)
    – Jeff Schaller
    Jul 1 at 13:36












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





How to use bash's "case" statement for "very specific" string patterns (multiple words, including spaces) ?



The problem is: I receive a multi-word String from a function which is pretty specific, including a version number. The version number now changes from time to time. Instead of adding more and more specific string patterns to my case statement, I would like to use a joker (or whatever the word for this is, like "Ubuntu 16.04.? LTS" or "Ubuntu 16.04.* LTS" . However, I didn't find any solution to this yet.



See this shell script I used so far:



 .
.
.
case "$OS" in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
"Ubuntu 16.04.3 LTS" | "Ubuntu 16.04.4 LTS" )
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;
.
.
.






share|improve this question














How to use bash's "case" statement for "very specific" string patterns (multiple words, including spaces) ?



The problem is: I receive a multi-word String from a function which is pretty specific, including a version number. The version number now changes from time to time. Instead of adding more and more specific string patterns to my case statement, I would like to use a joker (or whatever the word for this is, like "Ubuntu 16.04.? LTS" or "Ubuntu 16.04.* LTS" . However, I didn't find any solution to this yet.



See this shell script I used so far:



 .
.
.
case "$OS" in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
"Ubuntu 16.04.3 LTS" | "Ubuntu 16.04.4 LTS" )
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;
.
.
.








share|improve this question













share|improve this question




share|improve this question








edited Jul 2 at 16:25

























asked Apr 3 at 13:58









Axel Werner

3581314




3581314











  • PS: i read the "pattern" part of the manual and tested some variations of "jokers", but it always failed, since i just forgot to simply drop the doublequotes and to escape the whitespaces. duh!
    – Axel Werner
    Apr 3 at 14:17






  • 1




    I think the term you might be thinking of is "wildcard" (for joker)
    – Jeff Schaller
    Jul 1 at 13:36
















  • PS: i read the "pattern" part of the manual and tested some variations of "jokers", but it always failed, since i just forgot to simply drop the doublequotes and to escape the whitespaces. duh!
    – Axel Werner
    Apr 3 at 14:17






  • 1




    I think the term you might be thinking of is "wildcard" (for joker)
    – Jeff Schaller
    Jul 1 at 13:36















PS: i read the "pattern" part of the manual and tested some variations of "jokers", but it always failed, since i just forgot to simply drop the doublequotes and to escape the whitespaces. duh!
– Axel Werner
Apr 3 at 14:17




PS: i read the "pattern" part of the manual and tested some variations of "jokers", but it always failed, since i just forgot to simply drop the doublequotes and to escape the whitespaces. duh!
– Axel Werner
Apr 3 at 14:17




1




1




I think the term you might be thinking of is "wildcard" (for joker)
– Jeff Schaller
Jul 1 at 13:36




I think the term you might be thinking of is "wildcard" (for joker)
– Jeff Schaller
Jul 1 at 13:36










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










You can use patterns in case statements, however you can't quote them so you have to escape whitespace.



case $OS in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
Ubuntu 16.04.[3-4] LTS)
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;





share|improve this answer






















  • @StephenKitt updated.
    – Jesse_b
    Apr 3 at 14:08










  • doh!! Escaping the spaces is the solution . sometimes im blind for the easiest solution. thanks. So this did the trick for me: ` Ubuntu 16.04.* LTS )`
    – Axel Werner
    Apr 3 at 14:09







  • 5




    You could also quote the literal parts but not the wildcards: 'Ubuntu 16'*) -- I find that to be more readable than backslashes
    – glenn jackman
    Apr 3 at 14:55











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',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
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%2f435287%2fhow-to-use-joker-or-wildcard-in-string-patterns-spaces-separated-words-in-a%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










You can use patterns in case statements, however you can't quote them so you have to escape whitespace.



case $OS in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
Ubuntu 16.04.[3-4] LTS)
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;





share|improve this answer






















  • @StephenKitt updated.
    – Jesse_b
    Apr 3 at 14:08










  • doh!! Escaping the spaces is the solution . sometimes im blind for the easiest solution. thanks. So this did the trick for me: ` Ubuntu 16.04.* LTS )`
    – Axel Werner
    Apr 3 at 14:09







  • 5




    You could also quote the literal parts but not the wildcards: 'Ubuntu 16'*) -- I find that to be more readable than backslashes
    – glenn jackman
    Apr 3 at 14:55















up vote
2
down vote



accepted










You can use patterns in case statements, however you can't quote them so you have to escape whitespace.



case $OS in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
Ubuntu 16.04.[3-4] LTS)
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;





share|improve this answer






















  • @StephenKitt updated.
    – Jesse_b
    Apr 3 at 14:08










  • doh!! Escaping the spaces is the solution . sometimes im blind for the easiest solution. thanks. So this did the trick for me: ` Ubuntu 16.04.* LTS )`
    – Axel Werner
    Apr 3 at 14:09







  • 5




    You could also quote the literal parts but not the wildcards: 'Ubuntu 16'*) -- I find that to be more readable than backslashes
    – glenn jackman
    Apr 3 at 14:55













up vote
2
down vote



accepted







up vote
2
down vote



accepted






You can use patterns in case statements, however you can't quote them so you have to escape whitespace.



case $OS in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
Ubuntu 16.04.[3-4] LTS)
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;





share|improve this answer














You can use patterns in case statements, however you can't quote them so you have to escape whitespace.



case $OS in
"SUSE Linux Enterprise Server 11 SP4")
echo "SLES11 detected."
;;
Ubuntu 16.04.[3-4] LTS)
echo "UBUNTU16 detected."
;;
"CentOS Linux 7 (Core)")
echo "CENTOS7 detected."
;;
*)
echo "Unknown OS detected. Quitting for safety reasons."
exit -1
;;






share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 3 at 14:15

























answered Apr 3 at 14:00









Jesse_b

10.4k22658




10.4k22658











  • @StephenKitt updated.
    – Jesse_b
    Apr 3 at 14:08










  • doh!! Escaping the spaces is the solution . sometimes im blind for the easiest solution. thanks. So this did the trick for me: ` Ubuntu 16.04.* LTS )`
    – Axel Werner
    Apr 3 at 14:09







  • 5




    You could also quote the literal parts but not the wildcards: 'Ubuntu 16'*) -- I find that to be more readable than backslashes
    – glenn jackman
    Apr 3 at 14:55

















  • @StephenKitt updated.
    – Jesse_b
    Apr 3 at 14:08










  • doh!! Escaping the spaces is the solution . sometimes im blind for the easiest solution. thanks. So this did the trick for me: ` Ubuntu 16.04.* LTS )`
    – Axel Werner
    Apr 3 at 14:09







  • 5




    You could also quote the literal parts but not the wildcards: 'Ubuntu 16'*) -- I find that to be more readable than backslashes
    – glenn jackman
    Apr 3 at 14:55
















@StephenKitt updated.
– Jesse_b
Apr 3 at 14:08




@StephenKitt updated.
– Jesse_b
Apr 3 at 14:08












doh!! Escaping the spaces is the solution . sometimes im blind for the easiest solution. thanks. So this did the trick for me: ` Ubuntu 16.04.* LTS )`
– Axel Werner
Apr 3 at 14:09





doh!! Escaping the spaces is the solution . sometimes im blind for the easiest solution. thanks. So this did the trick for me: ` Ubuntu 16.04.* LTS )`
– Axel Werner
Apr 3 at 14:09





5




5




You could also quote the literal parts but not the wildcards: 'Ubuntu 16'*) -- I find that to be more readable than backslashes
– glenn jackman
Apr 3 at 14:55





You could also quote the literal parts but not the wildcards: 'Ubuntu 16'*) -- I find that to be more readable than backslashes
– glenn jackman
Apr 3 at 14:55













 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f435287%2fhow-to-use-joker-or-wildcard-in-string-patterns-spaces-separated-words-in-a%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)