Friday, June 28, 2013

Linux Scripting: Lesson 1

Writing your first Shell script:

To successfully write a shell script, we have to do three things:

1. Write a script
2. Give permission to the shell to execute it
3. Put it somewhere the shell can find it

Writing a script

A shell script is a file that contains ASCII text. To create a shell script, you use a text editor. There are many text editors available for Linux system. Some of the popular ones are vi, vim, emacs, nano, gedit, kmacs

I am going to use VIM to write my first script. Now lets start it.

NOTE: write the commands only between the <>which  i will mention below

1. Login to your linux machine and type <vim>
Now you are into a text editor.
2. Press <i> to start typing in the text editor.
3. Type following 
< #!/bin/bash
   # My first script
       echo "Hello my name is Billy Jean!">
4. Type <:w billyjean> (This will save your script as billyjean)
5. Type <:wq!>  (This will let you exit from the text editor)
6. Type <chmod 777 billyjean(This will give full permission to run the script)
7. Type <./billyjean(This should display what you have written in between "" after echo)



No comments:

Post a Comment