O'Reilly logo

Mastering Bash by Giorgio Zarrelli

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The case statement

When you are given more alternatives, you can process them with a sequence of if else statements:

if [condition];thencommandelsecommandfi

The if clauses can be nested if needed, but in the long run, having more than a few choices messes up the code, making it less readable. One of the basic mantras of coding is exactly keeping the code readable, making it elegant since elegance here does not simply mean beautiful, but also consistent over time. Always keep a meaningful indentation so that the clauses will outstand. Try to use as little code as you can, adopt the same notation all through your script, and make it all compact and lean. So, having a cascade of if/then/else/fi with a lot of indentation cannot show up as the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required