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
69
votes
3 answers

How does the #! shebang work?

In a script you must include a #! on the first line followed by the path to the program that will execute the script (e.g.: sh, perl). As far as I know, the # character denotes the start of a comment and that line is supposed to be ignored by the…
mocybin
  • 997
  • 1
  • 8
  • 11
68
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
  • 128,757
  • 147
  • 397
  • 562
67
votes
7 answers

env: python\r: No such file or directory

My Python script beak contains the following shebang: #!/usr/bin/env python When I run the script $ ./beak, I get env: python\r: No such file or directory I previously pulled this script from a repository. What could be the reason for this?
Niklas R
  • 16,299
  • 28
  • 108
  • 203
56
votes
8 answers

What should I use for a Perl script's shebang line?

Which of these is better or faster to use as the shebang line for a Perl script? #! perl #! perl.exe #! fullpath/perl(/perl.exe) #! partialpath/perl(/perl.exe) And, when using #!perl, when it works on a particular system, how do I find out in…
Anonymous
  • 561
  • 1
  • 4
  • 3
53
votes
10 answers

What's the appropriate Go shebang line?

I like using shebangs to run my Perl scripts directly: #!/usr/bin/env perl What's the shebang for Go programs?
mcandre
  • 22,868
  • 20
  • 88
  • 147
53
votes
5 answers

Shebang doesn't work with python3

I have the following program: #!/usr/local/bin/python3 print("Hello") Via terminal I do test.py and I get: Traceback (most recent call last): File "/usr/lib/python3.3/site.py", line 629, in main() File…
zer0uno
  • 7,521
  • 13
  • 57
  • 86
44
votes
8 answers

Should I use a Shebang with Bash scripts?

I am using Bash $ echo $SHELL /bin/bash and starting about a year ago I stopped using Shebangs with my Bash scripts. Can I benefit from using #!/bin/sh or #!/bin/bash? Update: In certain situations a file is only treated as a script with…
Zombo
  • 1
  • 62
  • 391
  • 407
42
votes
7 answers

shebang: use interpreter relative to the script path

I try to build scripts that work everywhere and always. For this I use a custom-built python, which is always in the parent directory relative to the script. This way I could load my package on an USB-stick and it would work everywhere, regardless…
Robby75
  • 3,285
  • 6
  • 33
  • 52
39
votes
6 answers

Use shebang/hashbang in Windows Command Prompt

I'm currently using the serve script to serve up directories with Node.js on Windows 7. It works well in the MSYS shell or using sh, as I've put node.exe and the serve script in my ~/bin (which is on my PATH), and typing just "serve" works because…
Adam M-W
  • 3,509
  • 9
  • 49
  • 69
39
votes
4 answers

Invoking a script, which has an awk shebang, with parameters (vars)

I have an awk script that I have defined thus: #!/usr/bin/env awk BEGIN { if (!len) len = 1; end = start + len } { for (i = start; i < end; i++) { print $1 } } I have saved it as columns and chmod +x'd it. I want invoke it so that start and end are…
Ollie Saunders
  • 7,787
  • 3
  • 29
  • 37
37
votes
3 answers

what is the use of "#!/usr/local/bin/ruby -w" at the start of a ruby program

what is the use of writing the following command at the start of a ruby program ? #!/usr/local/bin/ruby -w Is it OS specific command? Is it valid for ruby on windows ? if not, then what is an equivalent command in windows ?
simminni
  • 873
  • 3
  • 9
  • 13
34
votes
3 answers

Shebang line limit in bash and linux kernel

I'm trying to execute python scripts automatically generated by zc.buildout so I don't have control over them. My problem is that the shebang line (#!) is too long for either bash (80 character limit) or direct execution (some Linux kernel constant…
sortega
  • 1,128
  • 9
  • 15
33
votes
1 answer

How can I use a shebang in a PowerShell script?

I have several PowerShell scripts that I'd like to invoke directly as a command from a Bash shell in Cygwin. For example, if I write a script with the filename Write-Foo.ps1, I'd like to execute it as a command from any working directory: $…
Cy Rossignol
  • 16,216
  • 4
  • 57
  • 83
32
votes
5 answers

How to add shebang #! with php script on linux?

I'm having a little issue with adding shebang #! with my php script on RedHat linux. I have a small piece of test code with shebang added (I've tried different variations as well), but I get the following error message everytime I try to run the…
user2799603
  • 873
  • 3
  • 13
  • 19
32
votes
4 answers

Why should the shebang line always be the first line?

I have a simple perl script as below: #!/usr/bin/perl use strict; use warnings; print "hello world!\n"; I can execute this script as below: >temp.pl hello world! > If I add some comments like this: #this script is just for test #the…
Vijay
  • 65,327
  • 90
  • 227
  • 319
1
2
3
32 33