Find more Info related to your curiosities @ our FORUM
First Shell Script
Open up your favorite text editor. You can use any text editor to write the shell scripts.
Normally the shell scripts has the file extension .sh
In our example programs we will be saving the files with .sh extension.
firstshellscript.sh
-
The first line of every SHELL script is a commented line directed toward the interpreter.
firstshellscript.sh:
#!/bin/bash
Try the command: which bash
Use this location for your shell scripts.
Lets start with a simple script to print " Hello World "
Example:
#!/bin/bash
echo "Hello World"
Save it as " firstshellscript.sh ".
You will need to give execute permissions for your scripts.
Examples:
$ chmod +x firstshellscript.sh
or
$ chmod 755 firstshellscript.sh
Now how to run your script?
There are 3 different ways to run a shell script:
1. bash firstshellscript.sh
2. sh firstshellscript.sh
3. ./firstshellscript.sh
Try all the above.
In our examples we will be using any of these options.