Monday, January 3, 2011

The meaning of #!/bin/ksh

After the script finds a pound sign "#" it will interpret it as a comment and it won't run anything after, but when it finds a # followed by a ! the current shell script will interpret it as the spec file to interpret for the rest of the script file.

For identifying your script type we need to start the script with #! and the location of your shell file.


$ cat hello.ksh
#!/bin/ksh
echo "Hello World"
$ file hello.ksh
hello.ksh: Korn shell script text executable

Here I didn't change the filename, just the bash location, and the file type changes to bash.

$ cat hello.ksh
#!/bin/bash
echo "Hello World"
$ file hello.ksh
hello.ksh: Bourne-Again shell script text executable

Don't start a script without declaring the shell type, otherwise you will run your script in the current users shell and things might not run well...