Linux Bash Scripting for Beginners: Write Your Own Scripts

Make your work easier, understand bash scripts written by others and build your own from scratch
3.8 (31 ratings)
Instead of using a simple lifetime average, Udemy calculates a
course's star rating by considering a number of different factors
such as the number of ratings, the age of ratings, and the
likelihood of fraudulent ratings.
1,428 students enrolled
$19
$20
5% off
Take This Course
  • Lectures 32
  • Length 2.5 hours
  • Skill Level Beginner Level
  • Languages English
  • Includes Lifetime access
    30 day money back guarantee!
    Available on iOS and Android
    Certificate of Completion
Wishlisted Wishlist

How taking a course works

Discover

Find online courses made by experts from around the world.

Learn

Take your courses with you and learn anywhere, anytime.

Master

Learn and practice real-world skills and achieve your goals.

About This Course

Published 9/2015 English

Course Description

Have you ever been frustrated by that script that just did not work? Are you tired of searching the web for a ready-made script, hoping that it will fix your problem? Want to sit back and relax for a couple of seconds while your script performs the task that would have taken you two hours to accomplish manually? Then you have come to the right course!

This course will help you build your own scripts and understand the ones written by others. No more relying on scripts that others built and hoping that they will solve your custom problems. Just writing your own solutions to your own problems.

Take this course to get:

  • Learning by example, so that instead of going through boring theoretical concepts, you get to see exactly how each concept applies in practice.
  • Monthly challenges to help you gain experience and trust in your own abilities.
  • Interactive, supportive experience, as I promptly reply to your questions when things just don't work.
  • 30-day money back guarantee if you don't like this course for any reasons, no questions asked.


In short, you will learn the basic building blocks of bash, watch how a real-life utility is built, do the monthly challenges and solve coding problems in the discussion area to gain experience (did I mention the prizes?).

The first section covers basic building blocks that allow you to write your own shell scripts, which are presented in a learn-by-example fashion. Here you will learn about basic linux command line utilities used throughout the course, a simple script structure, defining functions, using input/output redirection, pipes and command substitution. The last lectures in this section focus on control statements, like if, case, while and for.

In the second section I will show you how to build a simple real-life utility for monitoring the amount of traffic on a network interface. There are two scripts involved in this utility. The "core", that queries system data about a network interface and adds it to a comma-separated-values (csv) file, one line at a time. The other one will take care of scheduling the "core" to be run at specific times, based on a user specified interval. The result is a csv file that contains data collected at specific points in time, data that can be later processed into a spreadsheet application (e.g. build graphs from it).

The rest of the course, what I call the dynamic part, is built in time. You will find here lectures on various command line utilities (e.g. find) or more in-depth lectures on subjects like redirection. I also post monthly challenges for you to gain some much needed experience, in order to ascend from a beginner to an intermediate level.

==========================================================

**** Monthly challenges (with prizes) ****

Jun '16: Utility to count the occurrences of a letter inside a text file

Mar '16: Textify, an utility that takes an integer number and converts it to text

Jan '16: Utility to equally space lines in a text file

Dec '15: Host ping reply time monitor

==========================================================

Update History

May 22nd 2016: Published solution for the January challenge

Feb 29th 2016: Published solution for the December challenge

Jan 3rd 2016: New lecture on xargs

Nov 22nd 2015: New section on standard end error output redirection

Nov 15th 2015: New lectures on the find utility and the proc filesystem.

Oct 10th 2015: New quiz on parameters

What are the requirements?

  • You need a linux pc/virtual machine
  • A text editor of your choice. I'm using text mode emacs, but nobody is forcing you to live in the past as well.
  • The bash shell

What am I going to get from this course?

  • Create and understand bash scripts.
  • Automate tasks in the Linux environment
  • Create a simple network monitoring utility in Linux
  • Schedule tasks to be run on a Linux system by using crontab
  • Define and use variables and functions in a bash script
  • Use basic Linux command line tools
  • Redirect output of command line tools using I/O redirection and pipes
  • Understand command substitution in the Linux command line environment
  • Many job ads list shell scripting as one of their requirements. Your chances in landing one of these will significantly increase

What is the target audience?

  • Junior software/network/QA engineers or students who would like to learn to use the linux bash shell efficiently
  • To make best use of this course you should take the time and work on the included challenges and exercises and take advantage from the interaction with your instructor. Just going through the materials can be done for free if you search deep enough.
  • If you are already familiar with bash scripts and linux command line utilities, this course is probably NOT for you

What you get with this course?

Not for you? No problem.
30 day money back guarantee.

Forever yours.
Lifetime access.

Learn on the go.
Desktop, iOS and Android.

Get rewarded.
Certificate of completion.

Curriculum

02:00

Introductory lecture: find out how this course is structured and who is its intended audience.

01:37

Brief overview about how this course works and quick glimpse at the Udemy interface.

Section 1: Basic bash Building Blocks
06:10

This lecture briefly describes the utilities used throughout the course and shows you some basic uses.

04:46

Going over the basic script structure, how to write comments, define and call functions.

09:39

This lecture shows you how to define and use variables.

Variables and Expansion
2 questions
06:37

Arguments are the way a script receives data from the outside world. This lecture goes over how you can access parameter values and manipulate them.

4 questions

A quick quiz on script arguments.

05:35

This lectures teaches you how to write output to a file, instead of the screen; and how to read input from a file, instead of the keyboard.

03:14

Pipes are a very powerful feature of the shell. This lecture shows you how to use them.

04:21

The fun part of using bash begins with command substitution. In this lecture you are going to learn how to replace a command name with its output.

Recap
4 questions
11:08

This lecture covers the 'if' statement and the syntax of the associated condition.

05:51

To avoid using multiple if/else if/else statements, use the 'case' statement, that matches an input expression to one of the given patterns.

05:50

This lecture covers the while/until loops.

14:38

Both forms of the 'for' loops, C-like and lists, are described in this lecture.

Section 2: The ifMonitor Project - Monitoring a Network Interface
Article

This document describes the ifMonitor project goals.

05:41

This is the first lecture on the check_iface script, the "core" of the ifMonitor project. This first part shows you how to parse the command line parameters of the script.

09:42

In this second lecture on the check_iface script, one line of data is written to the output file.

05:42

cron & crontab are used to schedule tasks at a specified time.

14:00

Using crontab to schedule the check_iface script.

Section 3: findutils - find, xargs, locate
03:14

Short overview on the proc filesystem. We will use files under this folder for the next lectures.

08:21

This lecture is about find and gives you an example of how to use it to search for files.

Mysterious if
1 question
00:51

Explanation for the question in the previous quiz.

3 questions

You should check the find (man find) documentation for the following quiz

04:21

xargs - an utility that lets you call other commands with parameters determined at runtime (as outputs of other commands)

2 questions

A few questions on xargs

Section 4: [Updated] Cheatsheet
3 pages

Cheatsheet

Section 5: More on redirection
03:48

Find out how to redirect normal output and errors to different files... or even to the same one.

1 question

Quick question about standard and error output redirection.

Standard vs. Error Redirection - part II
02:31
Error Redirection
1 question
Section 6: Challenges
1 page

General challenge rules

2 pages

Build an application that monitors the ping response time of several hosts.

1 page

Build a small tool that equally spaces lines in a file.

02:32
Create a script that receives one integer parameter and converts it to text.

Benefits:

  • practice arithmetic expansion
  • practice the case instruction
  • practice the if conditional expression with integers
  • good use of command substitution
  • the use of functions
00:32

Create a simple script that counts the occurrences of a letter inside a text file.


Check the bash manual (man bash) - the Parameter Expansion section - on how to find the length of a variable or how to get a substring (even of length one) from a word.

Section 7: [New] Challenge Solutions
07:53

This lecture will show you how to resolve the host monitor challenge. Besides that, you will take a quick look at getopt, check out a faster way to schedule recurring tasks using crontab and find out how to use the last command error status ($?).

You can download the scripts for this challenge, they are attached to this lecture.

02:22

Solving the file spacer challenge. This lecture will give you a quick insight into the workings of the IFS builtin variable.

Students Who Viewed This Course Also Viewed

  • Loading
  • Loading
  • Loading

Instructor Biography

Andrei Bunghez, Embedded Software Engineer | PM | Android Rookie

Hello! I am a passionate software engineer working mostly in the embedded networking world. I have a degree in Computer Science from the Politechnica University in Bucharest, major in Compilers and Operating Systems and have recently obtained an Android Developer Nanodegree from Udacity.

I have been an embedded software engineer for the past 12+ years, developing and maintaining software for a range of Ethernet devices. During this time I have been responsible for various parts of these systems, ranging from the higher levels of networking protocols like VLAN, STP, SNMP to chip drivers and distributed programming across Ethernet switches. At some point I started leading software releases and did a partial shift to project management, while still maintaining a keen interest in the embedded software practice. In the past few years I have added Android and Arduino on my list of interests and I am now working on a small pet project related to air quality, tying these two platforms together.

I usually prefer learning by example. So, it is only natural that this becomes my preferred way of teaching as well. My lectures are filled with examples that illustrate the main presented concept or topic.

I'm looking forward to seeing you in my courses!


Ready to start learning?
Take This Course