Learn Linux # part 4 ~ B) First sell script !

In Technology on November 4, 2012 at 3:00 am

There are different types of shells like

We will be writting scripts for bash shell .Check the type of shell you are using by typing the following command in linux terminal

$ ps -p $$                                   (Note :the first $ stands for the command prompt of your terminal )

OUTPUT should be something like this


5866 pts/0    00:00:00 bash  


There are many editors like nano,vi,gedit you can use any of those I would suggest using vi because it has advanced functionality and you won't have to switch later on.So keep practicing using vi.

So lets begin:

STEP 1 :open the editor type at the terminal prompt typing the following command:

$ vi 

This will start a new .sh file to write a shell script .

STEP 2 : Now you have to press i to get into insert mode so that you can start typing (without this you won't be able          to type)!

STEP 3 : type the following shell script .You can copy paste from below to see how the first script works
          #! /bin/bash    # Note the hash symbol is used for comment in shell script                           # the first line has to be as shown (don't worry I will tell you later why)
          echo "Hello you are reading this super awesome blog on linux ~ TECHLAVYA " 
                          #echo command is used for reflecting what you type within double quotes on the screen

STEP 4 : save the file and exit vi 

         this can be done by pressing the escape key (esc)  and then typing semicolon (:)  and then w and then q

         ie :wq            (Note: this will appear at the bottom of the terminal screen)

STEP 5 : give file permission by typing in the terminal

         chmod u+x

STEP 6 : run the shell scripts by typing in the terminal


OUTPUT will be :

      Hello you are reading this super awesome blog on linux ~ TECHLAVYA

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: