Logo

Bash Scripting Guide: First Script

In this section, we will guide you through the process of creating your first Bash script. This is an essential step to get hands-on experience with Bash scripting.

Table of Contents

  1. Creating a Bash Script
    1. Text Editors for Scripting
    2. Creating and Saving Your First Script
  2. Running a Bash Script
    1. Creating Executable
    2. Running Scripts

1 Creating a Bash Script

1.1 Text Editors for Scripting

Before creating a Bash script, choose a text editor for scripting. Common choices include nano, vim, or any text editor of your preference.

For example, using nano:


nano myscript.sh

1.2 Creating and Saving Your First Script

Inside the text editor, add the following lines to create a simple script:


#!/bin/bash

echo "Hello, Bash Scripting!"

Save the file and exit the text editor.

2 Running a Bash Script

2.1 Creating Executable

Make the script executable using the chmod command:


chmod +x myscript.sh

2.2 Running Scripts


$ ./myscript.sh
Hello, Bash Scripting!

If you want to run a script without making it executable, use the bash command:


bash myscript.sh

This allows you to run the script without changing its permission.


Continue to Part 3: Variables and Data Types.

Go back to Bash Scripting Guide.

Visit other Developer Guides.