Module 10 of 11

Shell Scripting

Lessons

About This Module

Anything you can type at the command line, you can also save in a file and run again whenever you like. That's a shell script, and it's how Linux users automate repetitive work: updating systems, backing up files, checking on services, and much more. This module teaches you to write scripts in Bash, the default shell on most distributions.

It starts with a first script: the shebang line, making a file executable with chmod, and running it. Then you'll learn how to store data in variables and make decisions with if statements. From there you'll repeat work with loops, organize your code into functions, handle many choices cleanly with case statements, and finish by learning where to store your scripts so you can run them from anywhere.

Type the examples out yourself instead of just watching, and test scripts on files you don't mind losing before pointing them at anything important. When you're comfortable writing scripts, continue on to Services, Logs & Security.

Lessons

7 videos
01

Your First Bash Script

Write a “Hello World” script, add the shebang line, make the file executable with chmod +x, and run it.

02

Variables

Store and reuse values in scripts: assign variables, read them back with $, capture command output, and avoid the common quoting mistakes.

03

If Statements

Make your scripts decide what to do with if, elif, and else, using test expressions to compare values and check files.

04

While Loops

Repeat commands for as long as a condition is true with while, and see how loops automate repetitive tasks.

05

Functions

Group related commands into reusable functions, call them from anywhere in a script, and keep your code shorter and easier to read.

06

Case Statements

Handle many possible values cleanly with case, a tidier alternative to a long chain of if and elif tests.

07

Where to Store Scripts

Choose sensible locations for your scripts, add them to your PATH, and run them like any other command from any directory.