BASH Conditionals Make Scripting AWESOME! (IF/THEN/ELSE/ELIF/CASE)

Описание к видео BASH Conditionals Make Scripting AWESOME! (IF/THEN/ELSE/ELIF/CASE)

IF/THEN/ELIF/ELSE/FI -- BASH conditionals are incredibly useful, but there are tons of things to learn! In this video we cover just about every conditional situation you might find yourself in, including using the CASE statement.

If you'd like to follow along, all the scripts I used are available to download here:
https://github.com/shawnp0wers/youtub...

It's a long video, so I've broken it up into chapters in case you want to refer back to a particular section later on:

00:00 - Intro
00:59 - Basic IF/THEN syntax
03:38 - Single and Double Brackets [ ] and [[ ]]
05:48 - How to use the read command to load variables
06:40 - Comparing strings
08:18 - Comparing multiple matches
11:59 - Using ELIF for multiple test conditions
14:07 - Using CASE for a simpler multi-condition scenario
18:04 - Nesting AND (&&) along with OR (||) for complex tests
20:52 - Filesystem checks (look for files/directories)
26:54 - Arithmetic tests (comparing integers)
32:30 - Doing math inside a conditional
34:00 - IF/THEN/ELSE Short Notation
35:15 - Outro and call for feedback!

As promised, here are some filesystem tests:
-a, -e (file exists)
-f (exists and is regular file, not directory or symlink)
-d (exists and is directory)
-h,-L (exists and is symlink)
-s (exists and is not empty, note: directory is never "empty")

And the common arithmetic tests:
(must be integers)
-gt (greater than)
-ge (greater than or equal to)
-eq (equal to)
-lt (less than)
-le (less than or equal to)
-ne (not equal to)

If you're enjoying this series, let me know in the comments!

#linux #bash #conditionals #scriptin #if #then #else #case

All My Online Homes are Here:
https://shawnp0wers.com

Check out my comic!
  / mybigroundworld  

Комментарии

Информация по комментариям в разработке