Is there an equivalent to PowerShell's “Switch” in bash?

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











up vote
2
down vote

favorite
1












I was curious as to whether or not there is an equivalent to PowerShell's "Switch" command that lets you maneuver with input instead of using a multitude of "if-statements"







share|improve this question



















  • If only there were such a construct in Python. Alas.
    – DopeGhoti
    Apr 19 at 18:48














up vote
2
down vote

favorite
1












I was curious as to whether or not there is an equivalent to PowerShell's "Switch" command that lets you maneuver with input instead of using a multitude of "if-statements"







share|improve this question



















  • If only there were such a construct in Python. Alas.
    – DopeGhoti
    Apr 19 at 18:48












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I was curious as to whether or not there is an equivalent to PowerShell's "Switch" command that lets you maneuver with input instead of using a multitude of "if-statements"







share|improve this question











I was curious as to whether or not there is an equivalent to PowerShell's "Switch" command that lets you maneuver with input instead of using a multitude of "if-statements"









share|improve this question










share|improve this question




share|improve this question









asked Apr 19 at 18:25









Paco R.

111




111











  • If only there were such a construct in Python. Alas.
    – DopeGhoti
    Apr 19 at 18:48
















  • If only there were such a construct in Python. Alas.
    – DopeGhoti
    Apr 19 at 18:48















If only there were such a construct in Python. Alas.
– DopeGhoti
Apr 19 at 18:48




If only there were such a construct in Python. Alas.
– DopeGhoti
Apr 19 at 18:48










1 Answer
1






active

oldest

votes

















up vote
11
down vote













If you're looking at a variable to determine flow, you want to use a case statement.



case "$var" in
val1)
do_something
;;
val2)
do_something_else
;;
esac


If you're looking to interactively get user input, you want to also use a select statement.



select action in proceed ponder perspire quit; do
case "$action" in
proceed)
go_on_then
;;
ponder)
have_a_think
;;
perspire)
exude_salty_secretions
;;
quit)
break
;;
esac
done





share|improve this answer

















  • 1




    Worth noting that it's matching against glob patterns. For example, if you write [Qq]uit|exit|go-*). It'd match "Quit", "quit", "exit", and anything beginning with "go-" like "go-elsewhere". default would be *), which is simply a glob that matches anything.
    – JoL
    Apr 19 at 22:51










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%2f438794%2fis-there-an-equivalent-to-powershells-switch-in-bash%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
11
down vote













If you're looking at a variable to determine flow, you want to use a case statement.



case "$var" in
val1)
do_something
;;
val2)
do_something_else
;;
esac


If you're looking to interactively get user input, you want to also use a select statement.



select action in proceed ponder perspire quit; do
case "$action" in
proceed)
go_on_then
;;
ponder)
have_a_think
;;
perspire)
exude_salty_secretions
;;
quit)
break
;;
esac
done





share|improve this answer

















  • 1




    Worth noting that it's matching against glob patterns. For example, if you write [Qq]uit|exit|go-*). It'd match "Quit", "quit", "exit", and anything beginning with "go-" like "go-elsewhere". default would be *), which is simply a glob that matches anything.
    – JoL
    Apr 19 at 22:51














up vote
11
down vote













If you're looking at a variable to determine flow, you want to use a case statement.



case "$var" in
val1)
do_something
;;
val2)
do_something_else
;;
esac


If you're looking to interactively get user input, you want to also use a select statement.



select action in proceed ponder perspire quit; do
case "$action" in
proceed)
go_on_then
;;
ponder)
have_a_think
;;
perspire)
exude_salty_secretions
;;
quit)
break
;;
esac
done





share|improve this answer

















  • 1




    Worth noting that it's matching against glob patterns. For example, if you write [Qq]uit|exit|go-*). It'd match "Quit", "quit", "exit", and anything beginning with "go-" like "go-elsewhere". default would be *), which is simply a glob that matches anything.
    – JoL
    Apr 19 at 22:51












up vote
11
down vote










up vote
11
down vote









If you're looking at a variable to determine flow, you want to use a case statement.



case "$var" in
val1)
do_something
;;
val2)
do_something_else
;;
esac


If you're looking to interactively get user input, you want to also use a select statement.



select action in proceed ponder perspire quit; do
case "$action" in
proceed)
go_on_then
;;
ponder)
have_a_think
;;
perspire)
exude_salty_secretions
;;
quit)
break
;;
esac
done





share|improve this answer













If you're looking at a variable to determine flow, you want to use a case statement.



case "$var" in
val1)
do_something
;;
val2)
do_something_else
;;
esac


If you're looking to interactively get user input, you want to also use a select statement.



select action in proceed ponder perspire quit; do
case "$action" in
proceed)
go_on_then
;;
ponder)
have_a_think
;;
perspire)
exude_salty_secretions
;;
quit)
break
;;
esac
done






share|improve this answer













share|improve this answer



share|improve this answer











answered Apr 19 at 18:33









DopeGhoti

40k54779




40k54779







  • 1




    Worth noting that it's matching against glob patterns. For example, if you write [Qq]uit|exit|go-*). It'd match "Quit", "quit", "exit", and anything beginning with "go-" like "go-elsewhere". default would be *), which is simply a glob that matches anything.
    – JoL
    Apr 19 at 22:51












  • 1




    Worth noting that it's matching against glob patterns. For example, if you write [Qq]uit|exit|go-*). It'd match "Quit", "quit", "exit", and anything beginning with "go-" like "go-elsewhere". default would be *), which is simply a glob that matches anything.
    – JoL
    Apr 19 at 22:51







1




1




Worth noting that it's matching against glob patterns. For example, if you write [Qq]uit|exit|go-*). It'd match "Quit", "quit", "exit", and anything beginning with "go-" like "go-elsewhere". default would be *), which is simply a glob that matches anything.
– JoL
Apr 19 at 22:51




Worth noting that it's matching against glob patterns. For example, if you write [Qq]uit|exit|go-*). It'd match "Quit", "quit", "exit", and anything beginning with "go-" like "go-elsewhere". default would be *), which is simply a glob that matches anything.
– JoL
Apr 19 at 22:51












 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f438794%2fis-there-an-equivalent-to-powershells-switch-in-bash%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?