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

437 questions
1246
votes
6 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…
Kurtosis
  • 14,401
  • 7
  • 25
  • 38
1151
votes
21 answers

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

It seems to me like the files run the same without that line.
john garcias
  • 11,607
  • 3
  • 14
  • 3
975
votes
13 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
  • 36,160
  • 18
  • 57
  • 89
556
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
  • 28,340
  • 55
  • 153
  • 242
452
votes
5 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
  • 20,669
  • 14
  • 52
  • 83
241
votes
6 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
  • 2,751
  • 2
  • 14
  • 18
153
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
  • 14,859
  • 42
  • 114
  • 188
130
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 -
  • 3,142
  • 3
  • 20
  • 31
125
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…
Hans-Peter Störr
  • 22,852
  • 27
  • 96
  • 134
108
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
  • 176,581
  • 46
  • 285
  • 363
84
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,115
  • 5
  • 24
  • 31
74
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,345
  • 2
  • 11
  • 18
71
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
  • 64,236
  • 45
  • 196
  • 319
66
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,382
  • 7
  • 32
  • 40
64
votes
1 answer

Proper shebang for Python script

I'm usually using the following shebang declaration in my Python scripts: #!/usr/bin/python Recently, I've came across this shebang declaration: #!/usr/bin/env python In the script documentation, it was noted that using this form is "more…
Adam Matan
  • 107,447
  • 124
  • 346
  • 512
1
2 3
29 30