4 basic fundamental things you should know about executing a shell script.
$ vim helloworld.sh #!/bin/sh echo "Hello World!"
1. Locate the shell executable and give it as she-bang #!
Identify the full path of where the shell is installed.$ which sh
/bin/sh
(or)
$ which ksh
$ which bash
Once you’ve identified the location of the shell executable, give that as shebang ( #! ) in the first line of shell-script file.$ vim helloworld.sh #!/bin/sh echo "Hello World!"
2. Assign Execute Permission to the Shell Script file
If you don’t have execute permission on the script, you’ll get “Permission denied” error message as shown below.$ ./helloworld.sh bash: ./helloworld.sh: Permission denied
If you want to give execute permission to group and others, do it as shown below.$ chmod 755 helloworld.sh
3.Executing the script just like a regular Linux command
You can execute a shell script either by using the absolute path or the relative path.sunitha@sunitha-laptop:~/bash_pgm$ ./hello.sh
hello world!