Questions tagged [shebang]

Use the tag /shebang if your question is about `#!`-string at the beginning of a script

Filter by
Sorted by
Tagged with
0 votes
0 answers
28 views

Why is it spelled `#!/usr/bin/env NAME` and not` '#!NAME` [duplicate]

Why isn't the default behavior of the shebang line to lookup the first argument as if it was a command? It seems like it is necessary to be a path to a tool. doesn't work(why?): #!bash works: #!/usr/...
Moberg's user avatar
  • 187
0 votes
0 answers
25 views

Unable to mount from a script using shebang (kernel hardening related ?)

I stumbled across a really weird issue with mount. I'm unable to make sense out of it. For some context, I wrote a Python script that aims to automount hot-pluggable USB devices, but this is not ...
ShellCode's user avatar
  • 225
1 vote
0 answers
488 views

How can I run the file currently open in the kate editor as a python script?

I am writing Python scripts and using a shebang line to specify the location of the Python interpreter in my system.: #!/usr/bin/env python So, in principle, my system should be able to run the ...
Fabio's user avatar
  • 437
1 vote
0 answers
69 views

How does the system decide which shell runs a script without a shebang line? [duplicate]

I have this "script" on my Arch Linux system: $ cat ~/scripts/foo.sh ps -hp $$ It will simply run ps on its own PID. But the script has no shebang line. I was expecting that in the absence ...
terdon's user avatar
  • 241k
0 votes
2 answers
341 views

Is there a Guix equivalent of nix-shell shebangs?

I want to write a script which executes within a specific guix shell environment. I'm hoping there's an equivalent version of the nix-shell shebang. For example, it would be cool to write something ...
kballou's user avatar
  • 162
4 votes
1 answer
937 views

Why don't we use #!command for the shebang line?

#!python3 print("Hello") I find that this code works fine in my terminal. But everyone does #!/path/to/file or #!/usr/bin/env command. Is there any reason to avoid using #!command in ...
egrr's user avatar
  • 43
5 votes
1 answer
1k views

How to make a Makefile executable?

I have a Makefile, and I want make to run automatically when I double-click it (from the Ubuntu file manager). So, I made this Makefile executable, and added at its top the following shebang line: #!/...
Erel Segal-Halevi's user avatar
2 votes
2 answers
236 views

Do executable shebang scripts always require LF line endings?

On Stack Overflow a comment to Can PowerShell Core handle ps1 files with CRLF line endings in Linux environments? asserted that executable files that use a shebang must use only the LF line ending, ...
Garret Wilson's user avatar
2 votes
1 answer
2k views

How does bash know about its parent's coprocess in this situation, and why does a shebang line change it?

outer.sh: ls -l /proc/$$/exe coproc cat ./inner.sh kill $! inner.sh: ls -l /proc/$$/exe set | grep COPROC || echo No match found coproc cat kill $! When I run ./outer.sh, this gets printed: ...
Joseph Sible-Reinstate Monica's user avatar
1 vote
1 answer
98 views

How to fake write-protected script's $0 (zeroth arg) to be a path where I have no write-access?

It's said relying on $0 in a script is dangerous (often citing to fake it: exec -a ...). Yes, in dirs where I have write-access I can symlink to a script to fake its $0. But how to make $0 point to a ...
bk-se's user avatar
  • 163
1 vote
3 answers
481 views

Make STDIN executable with shebang

I have a program to list database files. It is called direkly from the shell like db filename to list the whole file, or like db 'filename :: conditions' to list only selected elements ... Another ...
Andy A.'s user avatar
  • 207
2 votes
1 answer
283 views

#!/usr/bin/env hangs with NAME=VALUE

I'm trying to figure out exactly what the semantics of the shebang are. I can write a script like this: #!/usr/bin/env bash if [ -z "$FOO" ] then echo "No FOO" else echo &...
Angus L'Herrou's user avatar
1 vote
0 answers
149 views

Chicken-egg problem with the shebang line [duplicate]

The first line of any shell script must be the shebang line. The shebang line tells which interpreter should be used to execute the shell script. But it seems there's some logic issue here: If the ...
smwikipedia's user avatar
  • 1,203
8 votes
2 answers
1k views

Equivalent of executing a file (with shebang line) by entering its path?

Say I have a file hello: #!/bin/sh echo "Hello World!" Provided the executable bit is set on that file, I can execute it by entering its path on the prompt: $ ./hello Hello World! Is ...
Brecht Machiels's user avatar
-1 votes
2 answers
200 views

Is it possible to cause a interpreter infinite loop?

I'm considering a possible denial of service attack scenario, where a script cause a system resource outage by recursively invoking itself as interpreter. The principle is as follow: The script ...
DannyNiu's user avatar
  • 622
6 votes
1 answer
910 views

Detect if a script is being run via shebang or was specified as a command line argument

In the Pyenv project, we've had a peculiar problem. We are substituting python (and python*) with our Bash scripts ("shims") that select a Python executable to run at runtime. Now, some ...
ivan_pozdeev's user avatar
3 votes
1 answer
430 views

shebang on vagrant mount doesn't work: bad interpreter: Invalid argument

I run in a strange problem if I try to execute a file inside vagrant mount, but not outside: $ cat test #!/usr/bin/env node console.log('works!') $ ls -la test -rwxr-xr-x 1 vagrant vagrant 43 May ...
Anton Bessonov's user avatar
2 votes
3 answers
3k views

Would it be best for PowerShell scripts to also have a shebang?

Shell scripts are better when having a shebang like so: #!/bin/bash echo "The shebang above this line works like a typical a comment but with a purpose" PowerShell scripts are also shell ...
Abel Melquiades Callejo's user avatar
0 votes
2 answers
103 views

Can duplication of POSIX shebang (#!/bin/sh) when sourcing files into one piece cause problems, be it practical or in theory?

I recently started to develop my Linux POSIX shell scripts in a more structured way. Let me explain: Code [A] is being sourced by some code [B], just some minimal example: #!/bin/sh # REQUIREMENTS # ...
Vlastimil Burián's user avatar
3 votes
2 answers
511 views

FreeBSD shebang error

I would like to put shebang #!/bin/sh -eufo pipefail in my script. But there're several things strange: The script would fail with that shebang in FreeBSD but not when run on MacOS on FreeBSd, the ...
KFL's user avatar
  • 269
16 votes
2 answers
16k views

What does the `-eu` mean in `#!/bin/bash -eu` at the top of a bash script? (or any of `-abefhkmnptuvxBCHP`)

What does the eu mean after #!/bin/bash -eu at the top of a bash script? Normally I begin my bash scripts with this hashbang/shebang: #!/bin/bash but I just came across one with #!/bin/bash -eu and ...
Gabriel Staples's user avatar
0 votes
2 answers
833 views

Fix path used by shebang #!/usr/bin/perl and #!/usr/local/cpanel/3rdparty/bin/perl

I can't find anyone that can help me fix this issue. after a recent centos update my CGI scrips that use: #!/usr/local/cpanel/3rdparty/bin/perl or #!/usr/bin/perl are trying to use an old perl ...
Neijek's user avatar
  • 1
1 vote
1 answer
946 views

How do I know if my Python script has been called with the interpreter on the command line or as an executable (via shebang)?

Is there a way in a Python script to determine if the caller provided the interpreter on the command line or if the shebang line was used to determine the interpreter to use? As a simple example, ...
C Smith's user avatar
  • 63
1 vote
2 answers
174 views

Why does a shebang script run as init= have an euid of 0 when run from an initrd, but not otherwise?

I am trying to create my own PID 1 init script, to be called from the boot cmdline with init=/myscript. How can I make it work on a real filesystem, with any kernel? When it runs in an initrd, it ...
loser's user avatar
  • 13
1 vote
1 answer
2k views

Why would anyone use sh instead of bash? [closed]

I have to modify existing shell scripts and they start with #!/bin/sh What reason would someone use that on a system that also supports bash? I am tempted to change it but I want to make sure there'...
Mario's user avatar
  • 63
6 votes
1 answer
13k views

/bin/env : bad interpreter

I am on Linux Mint 19.03. I have a setup shell script file, setup.sh. When I run ./setup.sh muyustan@mint:~/Downloads/quartusExtracted$ ./setup.sh bash: ./setup.sh: /bin/env: bad interpreter: No ...
muyustan's user avatar
  • 253
0 votes
1 answer
171 views

Ways for making a Scala script standalone in Linux?

Programming Scala says: Invoking scripts with scala is tedious when you use these scripts frequently. On Windows and Unix-like systems, you can create standalone Scala scripts that don’t ...
Tim's user avatar
  • 101k
3 votes
2 answers
271 views

Pass options to AWK script bypassing AWK

Can I get arguments that happen to be AWK options passed directly to a pure AWK script? Example script: #!/usr/bin/env -S awk -f BEGIN { if (ARGV[1] == "-h") print "whoop" } I want ./myscript -h to ...
aaa's user avatar
  • 217
0 votes
1 answer
339 views

/usr/bin/env python runs on cmdline, fails in #! line [duplicate]

I'm trying to make a python script runnable, by adding the following "shebang" first line: #!/usr/bin/env python but when I run the file, I get: $ myscript.py : No such file or directory Now, if I ...
einpoklum's user avatar
  • 9,462
18 votes
2 answers
7k views

POSIX shell scripts shebang #!/bin/sh vs #!/usr/bin/env sh, any difference?

I recently noticed that many scripts are using /usr/bin/env in their shebang. I have seen that mainly using Bash and Python, but thus far never in conjunction with POSIX sh (ash, dash,...). I wonder ...
Vlastimil Burián's user avatar
1 vote
1 answer
24k views

/bin/ksh: bad interpreter: No such file or directory [duplicate]

I have script with #!/bin/ksh in the first line. When I try to execute this script (run ./myscript.sh) the error occurred: -bash: ./myscript.sh: /bin/ksh: bad interpreter: No such file or directory ...
Nik's user avatar
  • 13
0 votes
0 answers
556 views

sh -c in shebang [duplicate]

I have a file test with the content #!/bin/sh -c 'echo was called with $0' I if i execute it it with ./test, i would expect the OS to effectively execute sh -c 'echo was called with $0' ./test ...
keppla's user avatar
  • 173
9 votes
1 answer
9k views

Invalid option name error with shebang "#!/bin/bash -o pipefail" in script [duplicate]

I have a file named test.sh: #!/bin/bash -o pipefail echo "Running test" git diff HEAD^ HEAD -M --summary | grep delete | cut --delimiter=' ' -f 5 When I try to run this script as: ./test.sh I ...
firedrillsergeant's user avatar
1 vote
1 answer
620 views

Python script shebang behavior

I have a python script, in which I have the following shebang #!/usr/bin/python the script permissions are -rwxrwxrwx. 1 user user 709 script.py the owner of the script is the same as the user I use ...
dejanualex's user avatar
0 votes
1 answer
876 views

Set default interpreter in fish shell

I've installed mill on arch linux with fish as my default shell. Since the file /usr/bin/mill doesn't start with a shebang, fish won't execute the file. Instead it responds with $ mill Failed to ...
cheezsteak's user avatar
0 votes
2 answers
208 views

Why does second part of shebang have a priority?

I have python script running under different python executable than default one. I have python executables both in /usr/bin and in /mydir/mybins. If I run, I get: $which python /usr/bin/python And ...
Dims's user avatar
  • 3,255
3 votes
6 answers
5k views

shebang or not shebang

I want to use a program in the shebang, so I create a script named <myscript> with: #!<mypgm> I also want to be able to run <mypgm> directly from the command prompt. <mypgm> ...
Jacques's user avatar
  • 551
4 votes
3 answers
865 views

Who runs the interpreter for files that are execute-only?

If the current user only has execute (--x) permissions on a file, under which user does the interpreter (specified by #!/path/to/interpreter at the beginning of the file) run? It couldn't be the ...
ATLief's user avatar
  • 299
15 votes
6 answers
5k views

Is it correct to use /bin/sh in the hashbang if the Bourne shell isn't available in a distribution?

Generally, shell scripts contain the following comment at the first line of the script file: #!/bin/sh. According to the researches that I made, this is called "hash bang" and it is conventional ...
Goktug's user avatar
  • 611
16 votes
3 answers
3k views

Why is the behavior of the `#!` syntax unspecified by POSIX?

From the Shell Command Language page of the POSIX specification: If the first line of a file of shell commands starts with the characters "#!", the results are unspecified. Why is the behavior of #...
Harold Fischer's user avatar
17 votes
2 answers
2k views

How does this shebang that starts with a double hyphen (--) work?

I have found the following kind of shebang in the RosettaCode page: --() { :; }; exec db2 -txf "$0" It works for Db2, and a similar thing for Postgres. However, I do not understand the whole line. ...
AngocA's user avatar
  • 295
1 vote
1 answer
323 views

Why does a script without she-bang can be run? [duplicate]

As far as I understand, to make kernel execve a non-ELF file, the file must be a script started with a she-bang #!, but I have a script run successfully without it, why does this happen? xtricman⚓...
炸鱼薯条德里克's user avatar
0 votes
5 answers
2k views

Separate environment with different /bin/sh

I have a bunch of shell scripts which incorrectly assume /bin/sh to be equivalent to /bin/bash. E.g., they have the #!/bin/sh shebang, but use the source command instead of . (dot). I run Ubuntu 16, ...
Alex Che's user avatar
  • 261
3 votes
0 answers
440 views

Why do I need this shebang? [duplicate]

perldoc perlrun contains this example: #!/bin/sh #! -*-perl-*- eval 'exec perl -x -wS $0 ${1+"$@"}' if 0; But I don't understand why it might be needed. For example, if my perl interpreter ...
69 420 1970's user avatar
1 vote
2 answers
316 views

Why does shebang lead to a different process name than an explicit call?

Summary Using mirage as an example, a python program that begins with a shebang: #!/usr/bin/python ... Looking at /proc/<pid>/comm or using pgrep, it appears like ... ... the process name ...
Martin Drautzburg's user avatar
13 votes
3 answers
5k views

Why doesn't "ps ax" find a running bash script without the "#!" header?

When I run this script, intended to run until killed... # foo.sh while true; do sleep 1; done ...I'm not able to find it using ps ax: >./foo.sh // In a separate shell: >ps ax | grep foo.sh ...
StoneThrow's user avatar
  • 1,707
1 vote
0 answers
176 views

Upstart script with expect scripting

Please give me advices about expect scripting combined with an upstart script. There are 3 scripts that I am dealing with right now. Script A) Java program PATH: /opt/~~/manager Script B) ...
user286310's user avatar
0 votes
1 answer
620 views

Run python script without declare it interpreter

I have such a program to check methods of data from the command line: me at me in ~/Desktop/Coding/codes $ cat check_methods.py #! /usr/bin/env python from sys import argv methods = dir(eval(argv[1]))...
Wizard's user avatar
  • 2,493
2 votes
1 answer
2k views

How is a bash script executed via its filename as command name with and without shebang?

From bash manual: 3.7.2 Command Search and Execution After a command has been split into words, if it results in a simple command and an optional list of arguments, the following actions are ...
Tim's user avatar
  • 101k
1 vote
1 answer
2k views

/usr/bin/env: ‘awk -f’: No such file or directory [duplicate]

Linux shylock-archinux 4.15.15-1-ARCH #1 SMP PREEMPT Sat Mar 31 23:59:25 UTC 2018 x86_64 GNU/Linux My machine is above.Anyone know what happend? The script with shebang #! /usr/bin/env awk -f don't ...
Shylock Hg's user avatar