Bash Scripting Tutorial – Part 1

As you start getting advanced with Linux, you will want to start creating your own automated tasks and programs. These are essentially Bash Shell scripts and those scripts work almost in the same way as any other programming language.

A Bash Script is just a series of commands that Linux will run through to complete a certain task. The script can be simple or complex to understand, completely depending on the situation. Let’s jump into it.

You must have some basic knowledge of Terminal commands and any text editor can be used.

1. Before we begin, run the following command for the customary update check.

$ sudo apt-get update && sudo apt-get upgrade

2. Before we start creating any scripts, we create a folder where we can put all our scripts into using the following commands.

$ mkdir scripts

$ cd scripts

3. The bash script files are given (.sh) extension.

4. Let’s create our first simple script to output something in the terminal itself. First, open a script file using any text editor. I am using Leafpad. Add the following line : #!/bin/bash, then go to the next line and add : echo Hello Etechwall !.

5. The #!/bin/bash tells the system that you are going to use the Bash shell. The (#) denotes a commented line that is ignored by the system. The (!) exclamation mark will force the script to execute the line as a command. This (#!/bin/bash) is known as Hash-Bang.

6. Save the file and go back to the terminal. Entering the “ls” command will show you all the files. Our file for now is not executable, to make it executable. Use “chmod +x etechwall.sh“. Now the script is executable, to run the script – enter “./etechwall.sh“.

7. The output is displayed in the terminal. The echo command is responsible for this outputting. You can add any number of words after echo in the same line only.

8. Try this example using echo : “echo Hello Etechwall ! Today is $(date +%A)“. The $(date +%A) will call the system variable which stores the current day of the week.

This is enough for this section. We will be back with our next part. Stay Tuned !

More on Related Topics :

1. Understanding the History, Versions, and Main Components of UNIX

2. How to Disable IPv6 Leak on Linux ?

3. Understanding the System Startup and Remote Login in UNIX

4. How to use rm and rmdir commands in Linux ?

5. How to use VIM in Linux Terminal?

Biplab Das

Biplab Das

My name is Biplab Das. I’m a writer, Blogger, Youtuber and full time IT support engineer whose childhood obsession with science fiction never quite faded. A quarter-century later, the technology that I coveted as a kid is woven into the fabric of everyday life. I’ve spent the past years to learn these technologies, I recently published a book on computer science fundamentals. People say smartphones are boring these days, but I think everyone is beginning to take this wonderful technology marvel for granted.
Keep Digging Technology.

Sign up for our Newsletter

Sign Up for our Newsletter for daily Updates !

shares