Bash Scripting for Beginners: Complete Guide to Getting Started - Case Statements (Part 13)

preview_player
Показать описание
Welcome to LearnLinuxTV's brand new complete course on Bash Scripting! In this episode, we'll take a look at case statements.

*LEARN LINUX TV - YOUR HOME FOR LINUX-RELATED FUN AND LEARNING!*

*🎓 BRAND NEW UDEMY COURSES AVAILABLE!*
Check out my new courses on Udemy and learn something new!

*🐧 SUPPORT LINUX LEARNING!*
_Note: Royalties and/or commission is earned from each of the above links_

*⏰ TIME CODES*
00:00 - Intro
00:27 - A quick example of a Case Statement in Bash
05:58 - Taking our case statement script for a test run
08:08 - Introducing a while loop into our script

*OTHER BASH SCRIPTING SERIES EPISODES*

*🌐 LEARN LINUX TV ON THE WEB*

*⚠️ DISCLAIMER*
Learn Linux TV provides technical content that will hopefully be helpful to you and teach you something new. However, this content is provided without any warranty (expressed or implied). Learn Linux TV is not responsible for any damages that may arise from any use of this content. Always make sure you have written permission before working with any infrastructure and that you are compliant with all company rules, change control procedures, and local laws.

#tech #learnlinux #linuxcommands
Рекомендации по теме
Комментарии
Автор

It should be noted that ';;' is the most used operator for the end of a code block, which means: "Stop matching patterns as soon as one is succesful."
But there are others:
- ';&' = if the pattern matches, the code block of the next choice is executed, too, no matter if the pattern for that choice matches or not
- ';;&' = if the pattern matches, the code block of the next matching pattern is executed, too.

Nevertheless you have to use one operator at each end of a code block but the very last.

deprimarvin
Автор

Jay my brother, can you please make a similar series on:
-Nginx
-Apache
-RAID
-Git
-Any monitoring server like (Nagios, Zabbix or Prometheus)
-Docker and Kubernets

??
It would be great help to all the Linux SysAdmins over the world.

udayarpandey
Автор

Defining the default in case statements is actually very important, even if it is unreachable in theory users will always find that edge case you did not think of, either out of carelessness or of malice.

AlbusRegis
Автор

Great series Jay! Learning lots!! Please keep up the great work!!

jojobobbubble
Автор

Here is a cleaner solution combining the knowledge from the previous lesson (functions). A function that calls itself it's called recursive function (does the same job as the while loop while keeping all the logic inside the function scope without modifying any external state).

function prompt_favorite_distro () {
echo 'What is your favorite Linux distro?'

echo "1 - Arch"
echo "2 - CentOS"
echo "3 - Debian"
echo "4 - Mint"
echo "5 - Ubuntu"
echo "6 - Something else..."
echo "x - exit"

read -r distro;

case $distro in
1) echo "Arch is a rolling release";;
2) echo "Centos";;
3) echo "Debian";;
4) echo "Mint";;
5) echo "Ubuntu";;
6) echo "6 - Something else...";;
x) echo "Alright then, see ya." && exit 0;;
*) echo "$distro is not a valid option. Please select a valid option" && prompt_favorite_distro;;
esac
}

prompt_favorite_distro

paujoan
Автор

I believe that the single semicolon at the end of "read distro" line isn't necessary.

LinuxCloud
Автор

you don't need to create a variable "finished". You can just assign 1 to the 'distro' variable and it is still going to do the trick

madry
Автор

why is there a ; after the read distro ?

tbr
Автор

Hello!

Why did you use upper case letter X in chmod command but in Class 02 - Hello World you used lower case x?
Is it the same then?

angeltrasvina
Автор

I wish these would go a little faster. I just want to know the syntax nuances...I know how to program.

cagedtigersteve
Автор

its so weird to see ";;" and not just ";"

Leverquin