You should learn bash scripting as soon as possible

 You should learn bash scripting as soon as possible 

You should learn bash scripting as soon as possible

Today we are going to take a look at Bash Scripting, You should learn Bash-Scripting 

Requirements:- A Linux machine ( I will be using a kali-Linux docker container ), if you want to learn Docker Tutorial  & Basic Linux Commands are always there for you.

You should learn bash scripting as soon as possible

If you are using a docker container like me, you might have to install the tool called nano, its a terminal-based text editor ( as in windows we have a notepad in Linux you can consider it a terminal-based notepad )

What is a Bash?

Bash stands for Bourne again shell which is the replacement for the Bourne shell, it was released in 1989, and it has been used as a default login shell as most of the Linux-distro & also bash was one of the programs that Linus Torvald added to Linux.

For understanding, it's just the terminal or the command line through which we interact with the Linux os. 

It's the shell through which we run all our commands. 

Starting with the Bash Scripting 

You should learn bash scripting as soon as possible

The above command is showing us that we are logged in to our bash shell ( This command is just outputting the shell type we are logged in as a user )

Creating our first Bash scripting file

You should learn bash scripting as soon as possible

The nano is a terminal-based text editor and followed by the file name & the extension of the shell files which is .sh

You should learn bash scripting as soon as possible

The above is the interface for the nano ( terminal-based text editor )

You should learn bash scripting as soon as possible

This thing is called a shebang it's the way of telling the bash shell which scripting language are we using. In Linux, you might be using different programming languages like Python, Go, Shell, etc...


You should learn bash scripting as soon as possible

The above is an example of the simple bash script as you can see above there is a circled command named echo ( it's a command which output the string passed to it )...

And below is the way to exit out of the nano. If you want to exit out of nano you need 

ctrl + x & then y & then Enter key on your keyboard 

The ctrl + x represents the exit menu in nano. The y confirms that you want to exit out of nano, Then it asks you for the file name if given already it will ask to change or keep it as it is, Just press Enter key and your file is saved. 

Executing the bash script 

To execute our bash script there are several methods, but the method which I like the most is 

bash file-name.sh

The above command runs the bash script and gives you the output in the terminal window. You can also use the chmod command for this, but for now, we will be using the command that I have shown you...

You should learn bash scripting as soon as possible

As you can see above our bash script was executed successfully. 


As we have used the command echo in this post, you can also use some other commands of Linux in your bash script to ( This is for your practice to getting your hand on some Linux command nano & executing the bash scripting  )
  • Make a file when executing the bash script 
  • You can also use the ls command inside the shell script as when you run you will see what's inside the directory
  • You can also copy & move some stuff when executing the file 
The above is very basic scripts you can make very easily, The bash scripting is not only about doing this, we will be learning and making some more bash scripts in the future posts...


Stay Tuned ✌✌

Next Post Previous Post
No Comment
Add Comment
comment url