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

Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
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
;;
.
.
.
bash scripting case
add a comment |Â
up vote
2
down vote
favorite
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
;;
.
.
.
bash scripting case
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
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
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
;;
.
.
.
bash scripting case
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
;;
.
.
.
bash scripting case
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
add a comment |Â
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
add a comment |Â
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
;;
@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
add a comment |Â
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
;;
@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
add a comment |Â
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
;;
@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
add a comment |Â
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
;;
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
;;
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
add a comment |Â
@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
add a comment |Â
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
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
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
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
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
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