Linux Bash Shell Scripting Complete Guide Incl Awk Sed

Bash shell scripting tutorial, go from ZERO to HERO and let's dance your bash programming skills

Last updated 2022-01-10 | 4.7

- Be able to create PRO looking script with parameters
- Use functions in script
- Read files line by line using while loop

What you'll learn

Be able to create PRO looking script with parameters
Use functions in script
Read files line by line using while loop
Use math in scripts
Be able to decide if value of specific variable is a regular file or a directory
Store commands output into an array
Be able to do decision making based on match with regular expressions
Use SED and AWK to take your scripts into next level

* Requirements

* Basic knowleadge about linux commands is good to have - but not required
* Text editor of your choice (if you just don't want to watch lectures)
* Be able to open a terminal (or git bash if you dont have virtual machine and want to work in Windows environment)


Welcome to linux bash shell scripting course. I'am Richard and I will be your instructor. I have great knowleadge about shell scripting as throughout my carrer I had been working for Fortune 50 company, where I apart from taking care of 200+ Solaris servers wrote many scripts for keeping live easy :)

What is covered?

  • Basics of scripting - no worry you don't know anything about scripting by now

  • Sha-bang explanation - what it is and why the heck it is called sha-bang

  • Decision making

  • Regular expressions

  • Wildcards

  • For & While loops

  • Functions

  • Reading arguments using CASE structure

  • Getopt

  • Getopts

  • ...and many more

And what about AWK? Yes, it is covered here!  And what about SED? Also covered!  

Why I have created this course?

Many years back, when I was starting as UNIX administrator, I had many ideas how to improve specific things using scripts. But, I couldn't find any good resource, which would take me through all needed topic in one place. Somewhere I got great explanation about sha-bang while regular expressions for shell scripting were only mentioned. Somewhere was good explanation about decision making in if statement, but SED and AWK part was missing, and that use of SED and AWK was in my carrer really important. Basically I cannot imagine any single production script, where I wouldn't used SED or AWK, because without them you are not able to create that "magic" in your script. 

Many years later, I am here to share in one place what is really needed in order to create magic script. Not only how to create script, do some decision making in if statements, write functions, use arrays, but mainly how to combine everything including AWK and SED. I was creating this course in a way, which would help me a lot to create great scripts during start of my career. All needed things in one place. 

Please, watch my preview lectures to see what we are going to build in this course.

Who this course is for:

  • Everyone who wants to dive into shell scripting
  • Experienced users who would like to take their knowleadge to next level wit AWK and SED

Course content

11 sections • 102 lectures

Scripting - what it is all about? Preview 03:08

Invoking the script Preview 08:52

Sha-bang! Preview 07:24

Test quiz 1-1

Test your knowleadge of what we just learned.

Using variables in scripts Preview 04:06

Explicit definition - showcase Preview 07:17

Read command Preview 06:23

command substitution + time measurement Preview 06:40

Test quiz 1-2

Test what we have just learned

Math calculation Preview 03:06

Math Calculation - showcase Preview 09:12

Test quiz 1-3

Test what have you just learned

Playing with $ : arguments, arguments, arguments Preview 04:37

More on arguments - playing with IFS and assigning arguments value to a variable Preview 03:34

Redirection and Piping Preview 05:53

Redirection and Piping - showcase Preview 04:23

Exit status Preview 07:50

Test quiz 1-4

Check what have you just learned

Practice test 1-1

Test what have you just learned.

Explaining IF Preview 03:01

Mathematical comparisons Preview 09:21

String comparisons Preview 04:13

String comparison - you are not root?? Preview 10:03

Test Quiz 2-1

Test what we have just learned

Wildcards Preview 04:26

Wildcards - making linux command badass Preview 07:44

Wildcards - create backup script Preview 11:28

Regular expressions Preview 06:30

Regular expressions - is there any reachable ip address ?? Preview 12:41

Test quiz 2-2

Test what we have just learned

Filesystem related tests Preview 01:53

Interested what [ -f $FILENAME ], [ -d $PATH ] and other filesystem comparisons can do?

Filesystem related tests - testing files permissions Preview 12:56

&& and || - making IF statement shorter Preview 09:27

Explaining for loop Preview 05:17

for loop theory

Add commands output into all .txt files Preview 03:58

From real world: for what purpose we use for loop

Looping through all script arguments: "[email protected]" or "$*" ?? Preview 03:05

Explaining while loop Preview 03:26

Making own cat command with line numbering Preview 11:29

Explaining case Preview 02:10

Recheck users input Preview 13:29

Creating script with parameters [-f file] [--file file] [-h] [--help] Preview 14:07

(NEW) Manual Parsing vs Getopts vs Getopt Preview 07:28

(NEW) Getopts - showcase script Preview 06:34

(NEW) Getopt - showcase script Preview 11:10

Explaining Array Preview 02:43

Array - storing output of command into array and making some fun with its items Preview 06:23

Explaining Functions Preview 03:33

Making addition in a function Preview 05:07

Explaining AWK Preview 03:27

print, BEGIN{}, {}, END{} Preview 05:32

$1, $2, dollars everywhere Preview 05:19

searching pattern Preview 04:43

NF - number of fields Preview 03:00

NR - number of records Preview 02:33

FS - field separator Preview 03:38

RS - record separator Preview 03:04

variable assignment Preview 04:12

if-else Preview 04:19

for loop Preview 03:59

Building script with AWK Preview 02:27

AWK script PART 1 - reading arguments Preview 08:22

AWK script PART 2 - was the location set? Preview 04:40

AWK script PART 3 - searching for specific extension Preview 03:18

AWK script PART 4 - what about not existing extension? Preview 04:06

AWK script PART 5 - counting size of files using awk Preview 02:29

AWK script PART 6 - setting largest and smallest file Preview 07:28

AWK script PART 7 - printing statistics Preview 06:56

AWK script PART 8 - reading awk part from separate file Preview 05:02

Explaining SED Preview 04:40

p - print command and -n option Preview 05:02

a append/ i prepand Preview 02:11

d - delete command Preview 03:08

c - change command Preview 01:46

q - quit command Preview 02:51

-e option Run multiple sed commands Preview 02:48

-i option Changing files for sure Preview 02:44

e - perform shell commands Preview 02:56

Explaining s - substitute command Preview 02:48

s - substitute command showcase Preview 06:21

Building script with SED Preview 03:12

SED script PART 1 - structure for reading arguments Preview 06:07

SED script PART 2 - fixing space/tab issues Preview 06:29

SED script PART 3 - printing lines which don't have space/tab issues Preview 06:42

SED script PART 4 - line numbering Preview 04:02

SED script PART 5 - show spaces/tabs as a red background Preview 08:04

SED script PART6 - show spaces/tabs also at the end of lines Preview 06:16

SED script PART 7 - just to print it nicely Preview 05:26

scripts Preview 00:04

for downloading the scripts we have worked on.