|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| 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. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
It's to tell your shell what shell to you in executing the following statements in your shell script.
|
| The Following User Says Thank You to hell666 For This Useful Post: | ||
jameson (05-22-2012) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
is that all hell666??????
|
|
#4
|
|||
|
|||
|
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.
|
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
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. |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Thank you Killerserv.
-Nisha |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
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 | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk command to replace ";" with "|" and ""|" at diferent places in line of file | shis100 | Shell Programming and Scripting | 7 | 03-16-2011 08:59 AM |
| Make scipt except from "Y","y" and "yes" to take [Enter] as being "yes" | hakermania | Shell Programming and Scripting | 4 | 12-11-2010 09:24 AM |
| ps -ef | grep "string1" "string2" " "string3" | steve2216 | Shell Programming and Scripting | 11 | 09-03-2010 11:08 AM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-20-2007 12:52 AM |
|
|