|
1 |
| -==== |
2 |
| -real |
3 |
| -==== |
| 1 | +Shebang (Unix) |
| 2 | +From Wikipedia, the free encyclopedia |
| 3 | + It has been suggested that this article be merged with Interpreter directive. (Discuss) Proposed since June 2014. |
| 4 | +A "shebang" character sequence |
4 | 5 |
|
5 |
| -Description |
6 |
| ------------ |
7 |
| -Retrieves the real component of this number. |
| 6 | +In computing, a shebang (also called a sha-bang,[1][2][3] hashbang,[4][5] pound-bang,[2][6] or hash-pling[2][7]), is the character sequence consisting of the characters number sign and exclamation mark (that is, "#!") at the beginning of a script. |
| 7 | + |
| 8 | +Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the script.[8] For example, if a script is named with the path "path/to/script", and it starts with the following line: |
| 9 | + |
| 10 | + #!/bin/sh |
| 11 | + |
| 12 | +then the program loader is instructed to run the program "/bin/sh" instead (usually this is the Bourne shell or a compatible shell), passing "path/to/script" as the first argument. |
| 13 | + |
| 14 | +The shebang line is usually ignored by the interpreter because the "#" character is a comment marker in many scripting languages; some language interpreters that do not use the hash mark to begin comments (such as Scheme) still may ignore the shebang line in recognition of its purpose.[9] |
| 15 | + |
| 16 | +Contents |
| 17 | + |
| 18 | + 1 Syntax |
| 19 | + 2 Examples |
| 20 | + 3 Purpose |
| 21 | + 3.1 Strengths |
| 22 | + 4 Portability |
| 23 | + 4.1 Magic number |
| 24 | + 4.2 Security issues |
| 25 | + 5 Etymology |
| 26 | + 6 History |
| 27 | + 7 Notes |
| 28 | + 8 See also |
| 29 | + 9 References |
| 30 | + 10 External links |
8 | 31 |
|
9 | 32 | Syntax
|
10 |
| ------- |
11 |
| -**complex**. *real* |
12 | 33 |
|
13 |
| -Return Value |
14 |
| ------------- |
15 |
| -**float** |
| 34 | +The form of a shebang interpreter directive is as follows:[8] |
| 35 | + |
| 36 | + #! interpreter [optional-arg] |
| 37 | + |
| 38 | +The interpreter must be an absolute path to an executable[1] program (if this interpreter program is a script, it must contain a shebang as well). The optional‑arg should either not be included or it should be a string that is meant to be a single argument (for reasons of portability, it should not contain any whitespace). |
| 39 | +Examples |
| 40 | + |
| 41 | +Some typical shebang lines: |
| 42 | + |
| 43 | + #!/bin/sh — Execute the file using sh, the Bourne shell, or a compatible shell |
| 44 | + #!/bin/csh -f — Execute the file using csh, the C shell, or a compatible shell, and suppress the execution of the user’s .cshrc file on startup |
| 45 | + #!/usr/bin/perl -T — Execute using Perl with the option for taint checks |
| 46 | + |
| 47 | +Shebang lines may include specific options that are passed to the interpreter (see the Perl example above). However, implementations vary in the parsing behavior of options; for portability, only one option should be specified (if any) without any embedded whitespace. Further portability guidelines are found below. |
| 48 | +Purpose |
| 49 | + |
| 50 | +Interpreter directives allow scripts and data files to be used as system commands, hiding the details of their implementation from users and other programs, by removing the need to prefix scripts with their interpreter on the command line. |
| 51 | + |
| 52 | +Consider a Bourne shell script that is identified by the path "some/path/to/foo" and that has the following as its initial line: |
| 53 | + |
| 54 | +#!/bin/sh -x |
| 55 | + |
| 56 | +If the user attempts to run this script with the following command line (specifying "bar" and "baz" as arguments): |
| 57 | + |
| 58 | +some/path/to/foo bar baz |
| 59 | + |
| 60 | +then the result would be similar to having actually executed the following command line instead: |
| 61 | + |
| 62 | +/bin/sh -x some/path/to/foo bar baz |
| 63 | + |
| 64 | +If "/bin/sh" specifies the Bourne shell, then the end result is that all of the shell commands in the file "some/path/to/foo" are executed with the positional variables $1 and $2 set to "bar" and "baz", respectively. Also, because the initial number sign is the character used to introduce comments in the Bourne shell language (and in the languages understood by many other interpreters), the entire shebang line is ignored by the interpreter. |
16 | 65 |
|
17 |
| -Example |
18 |
| -------- |
19 |
| ->>> (1+3j).real |
20 |
| -1.0 |
| 66 | +However, it is up to the interpreter to ignore the shebang line; thus, a script consisting of the following two lines simply echos both lines to standard output when run: |
21 | 67 |
|
22 |
| -See Also |
23 |
| --------- |
24 |
| -`imag`_ |
| 68 | +#!/bin/cat |
| 69 | +Hello world! |
25 | 70 |
|
26 |
| -.. _imag: ../complex/imag.html |
| 71 | +Strengt |
0 commit comments