Questions tagged [shebang]

The #! marker at the beginning of scripts is called a shebang.

The #! marker at the beginning of scripts is called a shebang.

See

486 questions
1522
votes
7 answers

What is the preferred Bash shebang ("#!")?

Is there any Bash shebang objectively better than the others for most uses? #!/usr/bin/env bash #!/bin/bash #!/bin/sh #!/bin/sh - etc I vaguely recall a long time ago hearing that adding a dash to the end prevents someone passing a command to your…
bgibson
  • 17,379
  • 8
  • 29
  • 45
1345
votes
22 answers

Why do people write "#!/usr/bin/env python" on the first line of a Python script?

I see these at the top of Python files: #!/usr/bin/env python #!/usr/bin/env python3 It seems to me that the files run the same without that line.
john garcias
  • 13,555
  • 3
  • 16
  • 3
1213
votes
15 answers

Should I put #! (shebang) in Python scripts, and what form should it take?

Should I put the shebang in my Python scripts? In what form? #!/usr/bin/env python or #!/usr/local/bin/python Are these equally portable? Which form is used most? Note: the tornado project uses the shebang. On the other hand the Django project…
treecoder
  • 43,129
  • 22
  • 67
  • 91
652
votes
10 answers

Why do you need to put #!/bin/bash at the beginning of a script file?

I have made Bash scripts before and they all ran fine without #!/bin/bash at the beginning. What's the point of putting it in? Would things be any different? Also, how do you pronounce #? I know that ! is pronounced as "bang." How is #! pronounced?
node ninja
  • 31,796
  • 59
  • 166
  • 254
614
votes
6 answers

What is the difference between "#!/usr/bin/env bash" and "#!/usr/bin/bash"?

In the header of a Bash script, what's the difference between those two statements: #!/usr/bin/env bash #!/usr/bin/bash When I consulted the env man page, I get this definition: env - run a program in a modified environment What does it mean?
Salah Eddine Taouririt
  • 24,925
  • 20
  • 60
  • 96
303
votes
8 answers

Why is #!/usr/bin/env bash superior to #!/bin/bash?

I've seen in a number of places, including recommendations on this site (What is the preferred Bash shebang?), to use #!/usr/bin/env bash in preference to #!/bin/bash. I've even seen one enterprising individual suggest using #!/bin/bash was wrong…
spugm1r3
  • 3,381
  • 3
  • 17
  • 18
175
votes
5 answers

What does the line "#!/bin/sh" mean in a UNIX shell script?

I was going through some shell script tutorials and found the following sample program: #!/bin/sh clear echo "HELLO WORLD" Can anyone please tell me what the significance of the comment #!/bin/sh at the start is?
Jake
  • 16,329
  • 50
  • 126
  • 202
174
votes
4 answers

What exactly does "/usr/bin/env node" do at the beginning of node files?

I had seen this line #!/usr/bin/env node at the beginning of some examples in nodejs and I had googled without finding any topic that could answer the reason for that line. The nature of the words makes search it not that easy. I'd read some…
Gepser Hoil
  • 3,998
  • 4
  • 24
  • 34
139
votes
1 answer

Appropriate hashbang for Node.js scripts

I'm trying to create a script for node.js that will work in multiple environments. Particularly for me, I'm switching back and forth between OS X and Ubuntu. In the former, Node is installed as node, but in the latter it is nodejs. At the top of…
Explosion Pills
  • 188,624
  • 52
  • 326
  • 405
138
votes
10 answers

How to use multiple arguments for awk with a shebang (i.e. #!)?

I'd like to execute an gawk script with --re-interval using a shebang. The "naive" approach of #!/usr/bin/gawk --re-interval -f ... awk script goes here does not work, since gawk is called with the first argument "--re-interval -f" (not splitted…
Dr. Hans-Peter Störr
  • 25,298
  • 30
  • 102
  • 139
94
votes
6 answers

Shebang Notation: Python Scripts on Windows and Linux?

I have some small utility scripts written in Python that I want to be usable on both Windows and Linux. I want to avoid having to explicitly invoke the Python interpreter. Is there an easy way to point shebang notation to the correct locations on…
dsimcha
  • 67,514
  • 53
  • 213
  • 334
93
votes
9 answers

Cannot pass an argument to python with "#!/usr/bin/env python"

I needed to have a directly executable python script, so i started the file with #!/usr/bin/env python. However, I also need unbuffered output, so i tried #!/usr/bin/env python -u, but that fails with python -u: no such file or directory. I found…
Eskil
  • 3,385
  • 5
  • 28
  • 32
78
votes
1 answer

node and shebang : help executing via command line

My node installation is at: /usr/local/bin/node and I've added the shebang: #!/usr/local/bin/node to the top of the file and given my node app file the permissions 755, but when I try to run: > ./my-app I get the old: -bash: ./my-app: No such file…
asking
  • 1,435
  • 3
  • 13
  • 21
76
votes
3 answers

How does /usr/bin/env work in a Linux shebang line?

I know shebang line like this: #!/bin/sh but I found out I can also use shebang line like this: #!/usr/bin/env python3 This confuses me, can someone explain to me how Linux will process this one?
user1187968
  • 7,154
  • 16
  • 81
  • 152
73
votes
1 answer

What's the difference between python shebangs with /usr/bin/env rather than hard-path?

I used to use the shebang #!/usr/bin/env python When is it better to use #!/usr/bin/python What is the exact difference between them?
Ken
  • 3,922
  • 9
  • 39
  • 40
1
2 3
32 33