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
1 vote
1 answer
46 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 ...
user avatar
  • 153
0 votes
3 answers
139 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 ...
user avatar
  • 123
1 vote
1 answer
58 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 &...
user avatar
1 vote
0 answers
80 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 ...
user avatar
  • 1,041
7 votes
2 answers
835 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 ...
user avatar
0 votes
2 answers
153 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 ...
user avatar
  • 429
6 votes
1 answer
351 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 ...
user avatar
3 votes
1 answer
310 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 ...
user avatar
0 votes
3 answers
1k 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 ...
user avatar
-1 votes
2 answers
87 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 # ...
user avatar
3 votes
2 answers
258 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 ...
user avatar
  • 195
5 votes
2 answers
5k 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 ...
user avatar
0 votes
2 answers
416 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 ...
user avatar
  • 1
1 vote
1 answer
351 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, ...
user avatar
  • 43
1 vote
2 answers
118 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 ...
user avatar
  • 13
0 votes
1 answer
824 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'...
user avatar
  • 43
2 votes
1 answer
7k 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 ...
user avatar
  • 183
0 votes
1 answer
95 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 ...
user avatar
  • 89.6k
3 votes
2 answers
174 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 ...
user avatar
  • 187
0 votes
1 answer
90 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 ...
user avatar
  • 7,249
14 votes
1 answer
4k 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 ...
user avatar
1 vote
1 answer
16k 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 ...
user avatar
  • 13
0 votes
0 answers
359 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 ...
user avatar
  • 173
5 votes
1 answer
5k 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 ...
user avatar
1 vote
1 answer
383 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 ...
user avatar
0 votes
1 answer
649 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 ...
user avatar
0 votes
2 answers
150 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 ...
user avatar
  • 2,517
4 votes
6 answers
4k 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> ...
user avatar
  • 461
4 votes
3 answers
519 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 ...
user avatar
  • 219
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 ...
user avatar
  • 601
17 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 #...
user avatar
17 votes
2 answers
1k 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. ...
user avatar
  • 295
1 vote
1 answer
157 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⚓...
user avatar
1 vote
5 answers
1k 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, ...
user avatar
  • 261
3 votes
0 answers
395 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 ...
user avatar
1 vote
2 answers
179 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 ...
user avatar
13 votes
3 answers
4k 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 ...
user avatar
  • 1,259
1 vote
0 answers
157 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) ...
user avatar
  • 11
0 votes
1 answer
542 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]))...
user avatar
  • 2,291
2 votes
1 answer
1k 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 ...
user avatar
  • 89.6k
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 ...
user avatar
2 votes
2 answers
91 views

How shall I allow more than one arguments to the interpreter in a shebang in a script

From Glenn's reply: Read your execve(2) man page. The limitation on a single optional argument is OS dependent. Linux treats all words after the interpreter as one single argument If you ...
user avatar
  • 89.6k
1 vote
1 answer
356 views

Basic usage of /etc/cron/ (d): correct pattern for /etc/cron (daily/weekly/monthly)

I use Ubuntu 16.04 with Bash and I've created this extensionless, shebangless file /etc/cron.daily/cron_daily: for dir in "$drt"/*/; do if pushd "$dir"; then wp plugin update --all --allow-root wp ...
user avatar
  • 1,712
6 votes
2 answers
3k views

What are the pro's and con's in using the "-l" in a script shebang

I recently came up to an easy fix for a crontab logging issue and I am wondering what are the pro's and con's of using this specific fix (running a script with a "login shell flag"), as: #!/bin/bash -...
user avatar
  • 255
12 votes
6 answers
2k views

Too many shebang (script declaration) lines --- any way to reduce their amount?

I have a project comprised of about 20 small .sh files. I name these "small" because generally, no file has more than 20 lines of code. I took a modular approach because thus I'm loyal to the Unix ...
user avatar
  • 1,712
0 votes
0 answers
1k views

shebang and command parameters [duplicate]

I tried to pass parameters to bash in shebang of executable script: #! /usr/bin/env bash -ex false But I get an error: /usr/bin/env: ‘bash -ex’: No such file or directory Should I avoid to use /...
user avatar
2 votes
1 answer
445 views

cannot get scripts to run in a Lubuntu (Xenial) Minimal (+LXDE) VM with shebangs

I embarrassed myself a little here with a simple typo and a profound ignorance. Save yourself some grief: your hasbangs/shebangs must always have a leading /, such as #!/bin/bash be precise if you ...
user avatar
6 votes
6 answers
2k views

Fastest way to determine if shebang is present

If I have a file with #!/usr/bin/env foobar what is the fastest/best way to determine if this file has a hashbang? I hear you can just read the first 2 bytes? How?
user avatar
10 votes
3 answers
2k views

Can I use a variable content as a shebang? [closed]

I have a shell script in which I want to add a shebang. Given a variable defined as follows: SHEBANG="#!/bin/sh" My question is if I can use that variable in another script like this: $SHEBANG # ...
user avatar
1 vote
1 answer
443 views

Change the default executable for file with potentially missing shebang

I have a library - users are to create executable files, potentially with a hashbang to tell exec which executable to use. If they omit the hashbang, then I think most systems default to /bin/sh, I ...
user avatar