Menu
Coddy logo textTech

What Is A Shell Script

Part of the Fundamentals section of Coddy's Terminal journey — lesson 66 of 82.

So far, you've been typing commands one at a time in the terminal. But what if you need to run the same sequence of commands repeatedly? This is where shell scripts come in.

A shell script is simply a text file containing a series of commands. Instead of typing each command manually, you write them all in a file, and the shell executes them in order. Think of it as a recipe that the computer follows step by step.

Shell scripts typically have a .sh extension and start with a special line called a shebang:

#!/bin/bash

This line tells the system which interpreter should run the script. In this case, it's Bash. Everything after this line is just regular commands, the same ones you've been typing throughout this course.

Shell scripts are powerful because they let you automate repetitive tasks, combine multiple commands into a single action, and share your workflows with others. System administrators use them to manage servers, developers use them to set up projects, and everyday users create them to simplify their daily tasks.

In the upcoming lessons, you'll learn how to create, run, and enhance your own shell scripts with variables, user input, and logic.

challenge icon

Challenge

Easy

A shell script called hello.sh has been provided for you. Use the cat command to view its contents and see the structure of a basic shell script.

Notice the shebang line (#!/bin/bash) at the top, followed by regular commands that you already know.

Your output should display:

#!/bin/bash
echo "Hello from a shell script!"
echo "Today is a great day to learn."

Hint: Use cat hello.sh to view the script's contents.

Cheat sheet

A shell script is a text file containing a series of commands that the shell executes in order.

Shell scripts typically have a .sh extension and start with a shebang line:

#!/bin/bash

The shebang tells the system which interpreter should run the script (in this case, Bash).

After the shebang, you can write regular shell commands that will be executed sequentially.

Example of a basic shell script:

#!/bin/bash
echo "Hello from a shell script!"
echo "Today is a great day to learn."

Try it yourself

Terminal
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals