Introduction to Bash Scripting




In this blog we will see how we can create our script in Linux and we will also see how we can execute our script and we will learn how we can write our first ‘hello world’ script . A script is a text file that contains a sequence of command for our Linux based operating system . First of all lets open our terminal , We can press ctrl+alt+ t to do this .

1.We will use our Nano editor or creating a script so for creating a script you just need to write Nano and then the script name .Basic Command : $nano script_name.sh



2.First line which you write in a script is : #!bash_location . It’s a good practice to use this which is called hash Bank and then the location of your bash . To get the location of your bash . Command : $which bash .

So now first line will look like :

As script is a sequence of commands so we can normally write ls -l for long listing .

3.To execute it one need to give the execute permission to the script but we can check , without giving the permission let’s see what happens so to execute a script you just need to write dot forward slash and then the name of your script . Command : $./script_name.sh

To provide permission we can use the command : $ chmod +x script_name.sh .Now this will change the permission of a file to the execution so you can execute this script by giving this permission . Now you can execute the script file :

So when you execute this , it gives you the long listing of files .

4.With this scripting you can execute all sequence of command not only one command .For example we can do ls and then let’s echo hello world .

Now when you execute :

Scripting is much advanced than this so it has a functions and it has loops and if conditions etc.

This is about the introduction to Bash Scripting .


Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*