home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 45.1 Beyond the Basics Chapter 45
Shell Programming for the Initiated
Next: 45.3 Don't Need a Shell for Your Script?  Don't Use One
 

45.2 The Story of : # #!

Once upon a time, there was the Bourne shell. Since there was only "the" shell, there was no trouble deciding how to run a script: run it with the shell. It worked, and everyone was happy.

Along came progress, and wrote another shell. The people thought this was good, for now they could choose their own shell. So some chose the one, and some the other, and they wrote shell scripts and were happy. But one day someone who used the "other" shell ran a script by someone who used the "other other" shell, and alas! it bombed spectacularly. The people wailed and called upon their Guru for help.

"Well," said the Guru, "I see the problem. The one shell and the other are not compatible. We need to make sure that the shells know which other shell to use to run each script. And lo! the one shell has a `comment' called : , and the other a true comment called # . I hereby decree that henceforth, the one shell will run scripts that start with : , and the other those that start with # ." And it was so, and the people were happy.

But progress was not finished. This time he noticed that only shells ran scripts, and thought that if the kernel too could run scripts, that this would be good, and the people would be happy. So he wrote more code, and now the kernel could run scripts, but only if they began with the magic incantation: #! , and told the kernel which shell ran the script. And it was so, and the people were confused.

For the #! looked like a "comment." Though the kernel could see the #! and run a shell, it would not do so unless certain magic bits were set. And if the incantation were mispronounced, that too could stop the kernel, which, after all, was not omniscient. And so the people wailed, but alas!, the Guru did not respond. And so it was, and still it is today. Anyway, you will get best results from a 4BSD machine by using

#! /bin/sh

or

#! /bin/csh

as the first line of your script. #!  /bin/csh -f is also helpful on occasion [it's usually faster because csh won't read your .cshrc file (2.2 ) . -JP  ].

- CT


Previous: 45.1 Beyond the Basics UNIX Power Tools Next: 45.3 Don't Need a Shell for Your Script?  Don't Use One
45.1 Beyond the Basics Book Index 45.3 Don't Need a Shell for Your Script? Don't Use One

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System










??????????????@Mail.ru