Questions tagged [shebang]

In computing, a shebang is the character sequence consisting of the characters number sign and exclamation mark (that is, "#!") at the beginning of a script.

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

For example, if a script is named with the path "path/to/script", and it starts with the following line:

#!/bin/sh
14 questions
425
votes
4 answers

What is the difference between #!/bin/sh and #!/bin/bash?

if I write, #!/bin/bash echo "foo" or #!/bin/sh echo "foo" both yields same. I have seen some scripts starting with #!/bin/sh or #!/bin/bash. Is there any difference between them?
Rahul Virpara
  • 11,860
47
votes
3 answers

Is there a command for running a script according to its shebang line?

If I want to execute a bash script which doesn't have its execution permission set, I can do: bash script.sh What should I use instead of bash if the script isn't executable and I don't know the correct interpreter? Is there a command that looks up…
Aivar
  • 635
27
votes
3 answers

What type of path in shebang is more preferable?

In scripts, first line should specify the path to interpreter. But on different servers Linux, Unix, or BSD this path could be different. What is more preferable? #!/usr/bin/env bash or #!/bin/bash
18
votes
2 answers

How to make python shebang use python3?

I have a third party script that uses the shebang #!/usr/bin/env python. According to the python documentation, this is the correct form for scripts that are suitable for both Python v2 and Python v3…
Toby
  • 357
  • 2
  • 5
  • 11
3
votes
3 answers

What is this line at the top of many files?

I have seen many files which have this line as the first line in them. What exactly is this? #!/usr/bin/env python What does it mean? Why is it necessary?
hellodear
  • 4,833
3
votes
2 answers

What is the shebang ( #!/bin/bash).

why do we use shebang in the beginning of a shell script file. does the script will run without it. I tried running it without shebang in shell script but it didn't run.
2
votes
1 answer

Shebang line for Node does not work in Ubuntu 18

I have just created an Ubuntu 18.04 instance on AWS and copied an existing project over. The usual shebang line for Node #!/usr/bin/env node now doesn't work. It gave: #!/usr/bin/env: No such file or directory What could be wrong? My $PATH…
u936293
  • 731
1
vote
1 answer

How to determine shell under which my script runs ; problem because shebang influences the output of $$

I am running Ubuntu 22 ( "22.04.4 LTS (Jammy Jellyfish)") I understand that in any linux shell script the symbol $$ denotes the pid of the process running that script I have a shell script that needs to ensure it runs under bourne so it determines…
1
vote
0 answers

linux running a script on a mounted fritz-Box share result in "bad interpreter" in ubuntu 22.04, works on 18.04 (other shares work)

A script like: #!/usr/bin/env bash ... or #!/usr/bin/env python3 ... will result in (german): -bash: /mnt/Fritz-USB/FritzUSB/t.sh: /usr/bin/env: Defekter Interpreter: Eingabe-/Ausgabefehler translated: -bash: /mnt/Fritz-USB/FritzUSB/t.sh:…
1
vote
1 answer

Prompt string PS4 duplicating itself when using set -x

My OS: Ubuntu 18.04.5 LTS I use tracing for troubleshooting a script. I've notice different behaviors in the tracing depending on how I set it up. I would like to understand why it behaves this way. I normally activate tracing using set -x in my…
martin_0004
  • 1,063
  • 5
  • 12
  • 19
0
votes
1 answer

Python shebang line

I am trying to execute a script in python as a cgi script using apache2. However instead of executing, the file gets downloaded. I have allowed my python file to be an executable. I think this is happening because my shebang line is incorrect. So…
0
votes
1 answer

Ubuntu execute file without ./

Using a shebang line, I added the functionality to launch a TCL script using the wish shell. However, I can only quickly launch the file by typing ./filename.tcl in the terminal. I would like to know, is there a way to run the same script without…
Ranger
  • 3
0
votes
1 answer

Python 2 interpreter instead of 3 in Geany

On my PC, Python 2 and 3 are installed – a query of the versions, using the terminal, outputs the following: $ python2 --version Python 2.7.14 $ python3 --version Python 3.6.3 I would like to learn Python 3, and I use Geany under Xubuntu 17.10…
-4
votes
1 answer

What is "#!' in a script file?

$cat shebang.sed #! /bin/sed -f s/red/xxx/ s/BLUE/1234/ $./shebang.sed rgb lower (#1): "xxx green blue" UPPER (#2): "RED GREEN 1234" $sed -f shebang.sed rgb lower (#1): "xxx green blue" UPPER (#2): "RED GREEN 1234" I may guess what #! is doing.…
Smile
  • 1,129