Worth mentioning again ... "#! shebang"
by sundialsvcs from LinuxQuestions.org on (#6QW5A)
Of course, we have all had quite our fill of "bash scripts." However, I would now invite you to browse the source-code of the "major scripts" that you use every day.
You are very likely to discover that many of these begin with a line such as the following:
#!/usr/bin/perl
(Or maybe something even more "generic." But, I digress.)
My key point in this post is, literally: #!. Affectionately known as: "shebang." Which must appear as "line #1."
When this appears as the first line of an "executable" file, the specified language-processing program is launched and the remainder of the file is handed to it. The end-user is none the wiser. But, this now means that your "command-line script" is no longer limited to what is built-in to "bash."
(FYI: So far as I know, only one "shell" has ever attempted to imbed a "serious programming language" directly into itself. And this is Dr. Korn's ksh. Unfortunately, I can count on the fingers of one hand the number of actual client sites who actually used it.)
The "shebang" mechanism, in very typical Linux/Unix fashion, is elegant. And, extremely powerful. When you can, with a single "shebang," seamlessly enter into the entire world of "a true programming language and its vast contributed libraries," your "shell scripts" will never be the same.
(The "Perl" programming language particularly comes to my mind as an example of something which was particularly intended to support "commands," and "text-file processing." But, the beauty of the entire concept is that: "it is entirely up to you." PHP? Ruby? A brand-new language of your own invention? It all works the same.)
You are very likely to discover that many of these begin with a line such as the following:
#!/usr/bin/perl
(Or maybe something even more "generic." But, I digress.)
My key point in this post is, literally: #!. Affectionately known as: "shebang." Which must appear as "line #1."
When this appears as the first line of an "executable" file, the specified language-processing program is launched and the remainder of the file is handed to it. The end-user is none the wiser. But, this now means that your "command-line script" is no longer limited to what is built-in to "bash."
(FYI: So far as I know, only one "shell" has ever attempted to imbed a "serious programming language" directly into itself. And this is Dr. Korn's ksh. Unfortunately, I can count on the fingers of one hand the number of actual client sites who actually used it.)
The "shebang" mechanism, in very typical Linux/Unix fashion, is elegant. And, extremely powerful. When you can, with a single "shebang," seamlessly enter into the entire world of "a true programming language and its vast contributed libraries," your "shell scripts" will never be the same.
(The "Perl" programming language particularly comes to my mind as an example of something which was particularly intended to support "commands," and "text-file processing." But, the beauty of the entire concept is that: "it is entirely up to you." PHP? Ruby? A brand-new language of your own invention? It all works the same.)