To successfully write a shell script, you have to do three things:
- Write a script
- Give the shell permission to execute it
- Put it somewhere the shell can find it.
a simple hello world program-
#!/bin/bash # My first script echo "Hello World!"
save this program with the extension .sh eg- script.sh
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 script.sh
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]$ ./script.sh
You should see “Hello World!” displayed. If you do not, see what directory you really saved your script in, go there and try again.