Wow! It brings a lot of memories!
In the 1980s and early 1990s, there were two main shells: the Bourne shell ( /bin/sh ) and the C shell ( /bin/csh ).
The Bourne shell had very few user-friendly things. There were no aliases or wildcards. Therefore, most people liked using C Shell as the default shell.
However, Csh was a terrible scripting language. (See http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/ ). So you used the C shell as your shell, but you wrote your scripts in the Bourne shell, which had much better syntax.
However, there was a slight problem: since your default shell is C Shell, enter the shell script name at the command prompt, and C Shell will pick it up and try to execute it.
To get around this, you put : as the first line in your program. It was a Bourne shell comment, but it was an incorrect C Shell command. Thus, the script will not be able to work if you forget to put sh in front of it.
In the future, the system will find out if the first line was : it should be a Bourne script shell. And even later, you could put #: so this will be a comment, not a command. Some people put the name of the shell, /bin/sh next to it, to help remind people that they intended to run it as a Bourne script.
The C shell began to die out after Kornshell became popular. Around the same time, shebang ( #! ) Came out, but it was only for AT & T, not Berkeley derivatives. BSD systems did not receive shebang until the end of the 1980s. And the Sun people used the C Shell as their default shell until Solaris came out.
I did not see the program start with #: /bin/sh at the age of.
By the way, you usually run your scripts as follows:
This way you are using the version of Perl that is in your path, and you do not need to worry about which directory it is in. For example, if you start your script with
#! /usr/local/bin/perl
And, Perl is actually located in /usr/bin , your script will not run. The env program is always located in /usr/bin and is guaranteed to work. Of course, if you want to use a specific version of Perl, and not the one that is on the way, you would go for the first method.