0Pricing
DevOps Bootcamp · Lesson

First Bash Script & Shebang

Write your very first executable Bash script, understand the shebang line, and execute it from the terminal.

First Bash Script & Shebang is a free DevOps Bootcamp lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Intro to Bash Scripts

Welcome to Bash scripting! A Bash script is simply a text file containing a sequence of commands that the Bash shell can execute.

Think of it as a recipe for your computer. Instead of typing commands one by one, you write them all down in a script, and the computer follows the instructions.

Why Automate with Bash?

Bash scripts are powerful tools for automation. They help you:

  • Automate repetitive tasks: Save time by running complex sequences of commands with a single script.
  • Combine commands: Chain multiple commands together to perform sophisticated operations.
  • Manage systems: Perform common system administration tasks efficiently.
  • Create utilities: Build your own custom command-line tools.

Creating Your Script File

To create a Bash script, you just need a plain text file. A common convention is to give script files a .sh extension, like my_script.sh.

You can create an empty file from the terminal using the touch command:

touch my_script.sh

Then, you can open it with a text editor to add commands.

Simple Script Content

Let's start by adding a very basic command to our script file. The echo command simply prints text to the terminal.

If you were to open my_script.sh in a text editor, you'd add this line:

echo "Hello from my script!"

Meet the Shebang Line

For your script to run correctly, it needs a special first line called the shebang (pronounced 'she-bang'). It tells your system which interpreter (program) should execute the script.

The shebang starts with #! followed by the path to the interpreter.

`#!/bin/bash` Explained

For Bash scripts, the most common shebang is #!/bin/bash. This means the script should be executed using the Bash interpreter located at /bin/bash.

So, your my_script.sh file would now look like this:

#!/bin/bash
echo "Hello from my script!"

Granting Permissions

Before you can run a script directly by its name, you need to give it execute permissions. This tells the operating system that the file is an executable program.

We use the chmod +x command to add execute permissions. If your script is named my_script.sh, you'd type:

chmod +x my_script.sh

Without this, the system won't know it's a program!

Execute Your Script

Once your script has execute permissions, you can run it directly from the terminal. If you are in the same directory as the script, you prefix its name with ./.

The ./ means 'in the current directory'. Try running this example, assuming it's saved as runnable_script.sh and has permissions:

#!/bin/bash
# This script will now run!
echo "Success! My first executable script!"

Full Hello Script Demo

Here's a complete 'Hello World' style script, ready to be saved, made executable, and run.

Steps:

  • Save this code to a file (e.g., hello_world.sh).
  • Make it executable: chmod +x hello_world.sh.
  • Run it: ./hello_world.sh.
#!/bin/bash
# This script greets the world!

echo "Hello, World!"
echo "Welcome to Bash Scripting!"

Scripting Quiz

You've learned the essential steps to create and run your first Bash script. Let's quickly check your understanding.

Recap: First Script

Congratulations! You've just created and run your very first Bash script. Here's a quick summary:

  • Bash scripts automate command sequences.
  • The shebang line (#!/bin/bash) tells the system which interpreter to use.
  • Use chmod +x to make your script executable.
  • Run an executable script with ./script_name.sh.

Now you have the foundation to build more complex scripts!

Frequently asked questions

Is the “First Bash Script & Shebang” lesson free?

Yes — the full text of “First Bash Script & Shebang” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “First Bash Script & Shebang”?

Write your very first executable Bash script, understand the shebang line, and execute it from the terminal. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “First Bash Script & Shebang” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. First Bash Script & Shebang
  2. Variables and User Input
  3. Conditional Statements (if, else, elif)
  4. Working with Arrays in Bash
← Back to DevOps Bootcamp