Home > Unix > Shebang

Shebang

In computing, a shebang (also called a hashbang, hashpling, or pound bang) refers to the characters “#!” when they are the first two characters in a script file. Unix-like operating systems take the presence of these two characters as an indication that the file is indeed a script, and attempt to execute that script using the interpreter specified by the rest of the first line in the file. For instance, Bourne shell scripts always start with the first line:

#!/bin/sh

More precisely, a shebang line consists of a number sign and an exclamation point character (“#!“), followed by the (full) path to the interpreter program that will provide the interpretation. The shebang is looked for and used when a script is invoked directly (as with a regular executable), and largely to the end of making scripts look and act similarly to regular executables, to the operating system and to the user.

Example shebang lines

Some typical interpreters for shebang lines:

  • #!/bin/bash — Execute using the Bourne-again shell
  • #!/bin/bash -c '/bin/bash' — Execute using bash in the /bin/ directory, and calls bash inside the /bin/
  • #!/bin/csh — Execute using csh, the C shell
  • #!/bin/ksh — Execute using the Korn shell
Categories: Unix
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s