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

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

a simple hello world program-


# My first script
echo "Hello World!"

save this program with the extension .sh eg-

Setting permissions

The next thing we have to do is give the shell permission to execute your script. This is done with the chmod command as follows:

$ chmod 755

The “755” will give you read, write, and execute permission. Everybody else will get only read and execute permission. If you want your script to be private (i.e., only you can read and execute), use “700” instead.

Putting it in your path

At this point, your script will run. Try this:

[me@linuxbox me]$ ./

You should see “Hello World!” displayed. If you do not, see what directory you really saved your script in, go there and try again.