#!/bin/sh ?????

Post Reply
Message
Author
image
Posts: 7
Joined: 25. Dec 2002 1:01

#!/bin/sh ?????

#1 Post by image »

Hi!
Ich weiss, dass man mit der oben genannten Zeile eine Datei ausführbar macht.
Aber was genau bedeutet eigentlich diese Zeile ausgeschrieben? Muss diese Zeile
immer in der ersten Zeile einer Datei stehen?

Danke
image

Descartes

Re: #!/bin/sh ?????

#2 Post by Descartes »

> Ich weiss, dass man mit der oben genannten Zeile eine Datei ausführbar macht.
Nicht ganz korrekt. Ein gesetztes executable Flag (z.B. chmod +x DATEI) macht eine Datei ausführbar.
Allerdings sagt bei einem Shell Script ein gesetztes executable Flag noch rein gar nichts darüber aus, mit welchem Interpreter dieses Script verarbeitet werden soll. Genau hierzu ist die Shebang Zeile da.

Auszug aus <a href="http://www.perlboard.de/perlguide/Kap01.html#712829" target="_blank"><!--auto-->http://www.perlboard.de/perlguide/Kap01 ... <!--auto-->

<blockquote><hr>Wenn Sie auf Unix arbeiten, achten Sie unbedingt auf die erste Zeile (umgangssprachlich »sh'bang« oder »shebang-Zeile« genannt: »sh'«für den Sharp, das Kreuz, und »bang« für das Ausrufezeichen). Diese Zeile sagt Unix, mit welchem Programm es das Skript ausführen soll. Der einzige Haken dabei ist, dass die Pfadangabe in dieser Zeile dem korrekten Pfad zum Perl-Interpreter entsprechen muss. Wenn Sie ihn in /usr/local/bin/perl oder woanders in Ihrem System installiert haben, fügen Sie Ihren Pfad anstelle des Pfadnamens in Zeile 1 im Listing 1.1 ein.<hr></blockquote>

> Aber was genau bedeutet eigentlich diese Zeile ausgeschrieben?
> Muss diese Zeile immer in der ersten Zeile einer Datei stehen?

Zur Positionierung:
Direkt am Script Anfang (Zeile 1, Spalte 1).

Zur Bedeutung:
siehe <a href="http://www.hyperdictionary.com/dictionary/shebang" target="_blank"><!--auto-->http://www.hyperdictionary.com/dictiona ... <!--auto-->

<blockquote><hr>
From Jargon File (4.3.1, 29 Jun 2001) [jargon]

<b>shebang /sh*-bang/ n.</b> The character sequence "#!" that frequently begins executable shell scripts under Unix. Probably derived from "shell bang" under the influence of American slang "the whole shebang" (everything, the works).


From The Free On-line Dictionary of Computing (09 FEB 02) [foldoc]

<b>shebang</b>
<operating system> (Or "shebang line", "{bang path}")
/sh*-bang'/ (From "{sharp}" and "{bang}") The {magic cookie}

"#!" used in {Unix} to mark the start of a {script}, e.g. a {shell script} or {Perl script}.

Under {Unix}, if the first two bytes of an {executable} file are "#!", the {kernel} treats the file as a script rather than a {machine code} program. The word following the "!" (i.e., everything up to the first {whitespace}) is used as the {pathname} of the {interpreter}. For example, if the first line of an executable is

#!/usr/local/bin/perl

the script will be treated as a {Perl} script and passed as an argument to /usr/local/bin/perl to be interpreted. Some variants of Unix also allow one or more parameters to be passed to the interpreter, for example, you can write

#!/usr/bin/perl -w

and the script will be started as if you typed

/usr/bin/perl -w <filename>

on the command line. Also, most modern kernels ignore any whitespace between the "!" and the interpreter pathname. Even some modern kernels have fairly small limits (e.g. 32) on the length of line they will accept, making long pathnames and arguments somewhat unportable.
<hr></blockquote>

Post Reply