The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers > Answers to Frequently Asked Questions
.
google unix.com



Answers to Frequently Asked Questions FAQ for UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 03:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-20-2007 01:52 AM
how could i make a program mixed with many "|", "<" and ">" strugglingman High Level Programming 2 04-29-2006 08:11 AM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 04:15 AM
how to request a "read" or "delivered" receipt for mails plelie2 Shell Programming and Scripting 1 08-06-2002 03:26 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-12-2002
Nisha Nisha is offline
Registered User
  
 

Join Date: Jun 2002
Location: Chennai, India
Posts: 110
Cool What does "#! /usr/bin/ksh" mean?

Whenever we write a shell script the first statement would be #! /usr/bin/ksh or something of the same..

What does this signify??? I know # is a comment.. what is this ! for???

Give in your thoughts....


Thanks,
Nisha
  #2 (permalink)  
Old 07-12-2002
hell666 hell666 is offline
Registered User
  
 

Join Date: Jul 2002
Location: void
Posts: 53
It's to tell your shell what shell to you in executing the following statements in your shell script.
  #3 (permalink)  
Old 07-12-2002
Nisha Nisha is offline
Registered User
  
 

Join Date: Jun 2002
Location: Chennai, India
Posts: 110
Question

is that all hell666??????
  #4 (permalink)  
Old 07-12-2002
hell666 hell666 is offline
Registered User
  
 

Join Date: Jul 2002
Location: void
Posts: 53
Yes, that is it. But, this kind of comment should be in your first line of the script, only then does it take this form. Also, when your shell comes across this line, a new process is spawned and replaced with this shell of your choice, and it is this process which will parse your script.
  #5 (permalink)  
Old 07-12-2002
killerserv's Avatar
killerserv killerserv is offline Forum Advisor  
Unix Predator
  
 

Join Date: Dec 2000
Location: Phoenix, AZ
Posts: 670
On the first line of an interpreter script, the "#!", is the name of a program which should be used to interpret the contents of the file. For instance, if the first line contains "#! /bin/sh", then the contents of the file are executed as a shell script.

You can get away without this, but you shouldn't. All good scripts state the interpretor explicitly. The '!' is also known as intepreter for the script to recognise correct compiler to be used.
  #6 (permalink)  
Old 07-13-2002
Nisha Nisha is offline
Registered User
  
 

Join Date: Jun 2002
Location: Chennai, India
Posts: 110
Talking

Thank you Killerserv.


-Nisha
  #7 (permalink)  
Old 07-13-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
This will probably be more than you wanted to know, but here goes anyway....

Originally, we only had one shell on unix. When you asked to run a command, the shell would attempt to invoke one of the exec() system calls on it. It the command was an executable, the exec would succeed and the command would run. If the exec() failed, the shell would not give up, instead it would try to interpet the command file as if it were a shell script.

Then unix got more shells and the situation became confused. Most folks would write scripts in one shell and type commands in another. And each shell had differing rules for feeding scripts to an interpreter.

This is when the "#! /" trick was invented. The idea was to let the kernel's exec() system calls succeed with shell scripts. When the kernel tries to exec() a file, it looks at the first 4 bytes which represent an integer called a magic number. This tells the kernel if it should try to run the file or not. So "#! /" was added to magic numbers that the kernel knows and it was extended to actually be able to run shell scripts by itself. But some people could not type "#! /", they kept leaving the space out. So the kernel was exended a bit again to allow "#!/" to work as a special 3 byte magic number.
So
#! /usr/bin/ksh
and
#!/usr/bin/ksh
now mean the same thing. I always use the former since at least some kernels might still exist that don't understand the latter.

And note that the first line is a signal to the kernel, and not to the shell. What happens now is that when shells try to run scripts via exec() they just succeed. And we never stumble on their various fallback schemes.
Sponsored Links
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0