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
3
votes
2answers
72 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 ...
-2
votes
2answers
157 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 ...
0
votes
2answers
61 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 ...
0
votes
1answer
42 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, ...
1
vote
2answers
50 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 ...
0
votes
1answer
130 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'...
1
vote
1answer
762 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 ...
0
votes
1answer
57 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 ...
3
votes
2answers
97 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 ...
0
votes
1answer
36 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 ...
9
votes
1answer
1k 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 ...
1
vote
1answer
5k 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 ...
0
votes
0answers
177 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 ...
0
votes
1answer
2k 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 ...
1
vote
1answer
147 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 ...
0
votes
1answer
326 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 ...
0
votes
2answers
86 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 ...
4
votes
6answers
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> ...
4
votes
3answers
251 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 ...
15
votes
6answers
4k 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 ...
17
votes
3answers
2k 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 #...
16
votes
2answers
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. ...
1
vote
1answer
107 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⚓...
1
vote
5answers
757 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, ...
3
votes
0answers
282 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 ...
1
vote
2answers
103 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 ...
13
votes
3answers
3k 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 ...
1
vote
0answers
128 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) ...
0
votes
1answer
456 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]))...
2
votes
1answer
520 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 ...
1
vote
1answer
1k 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 ...
2
votes
2answers
73 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 ...
1
vote
1answer
266 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 ...
2
votes
2answers
1k 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 -...
12
votes
6answers
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 ...
0
votes
0answers
763 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 /...
2
votes
1answer
282 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 ...
3
votes
5answers
1k 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?
9
votes
3answers
1k 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 # ...
1
vote
1answer
317 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 ...
0
votes
1answer
436 views

#!/usr/bin/env foo #!vs /usr/bin/foo [duplicate]

Which of the above forms is "better" for running bash, python etc. scripts? Why can't I just do #!$(which foo)? Is it neccecery to specify full path to env? I gather from this answer, that the path /...
3
votes
2answers
815 views

xslt shbang: Using xslt from the command line

I have (foolishly?) written a couple of moderately general-purpose xslt scripts. I'd quite like to turn these into executables that read an xml document from standard in or similar. The way you do ...
53
votes
7answers
16k views

Multiple arguments in shebang

I am wondering whether there is a general way of passing multiple options to an executable via the shebang line (#!). I use NixOS, and the first part of the shebang in any script I write is usually /...
0
votes
2answers
320 views

What is the actual command executed when running a script with a shebang as its name with same arguments?

From bash manual about shebang Most versions of Unix make this a part of the operating system’s command execution mechanism. If the first line of a script begins with the two characters‘ #!’, ...
2
votes
1answer
1k views

Avoid passing environment variable to python script

I have a small python script #!/usr/bin/env python3 import some_python3_module def main(): # do stuff if __name__ == '__main__': main() and cannot run this script with Python3, since ROS ...
2
votes
1answer
461 views

Multiple arguments in shebang lines

Linux only supports one argument in a shebang line: This: #!/bin/sh cat > pr_args <<'EOF' #!/bin/sh -e printf "'%s'\n" "$@" EOF cat > shebang <<'EOF' #!pr_args a b c EOF chmod +x ...
2
votes
1answer
273 views

validity check all files in a folder depending on the shebang [closed]

I have a project with some lua and some bash files. I want to loop over all files and depending on the shebang I want to execute a validity check.
21
votes
3answers
8k views

Which shell interpreter runs a script with no shebang?

Suppose the default shell for my account is zsh but I opened the terminal and fired up bash and executed a script named prac002.sh, which shell interpreter would be used to execute the script, zsh or ...
17
votes
6answers
6k views

Choose interpreter after script start e.g. if/else inside hashbang

Is there any way to dynamically choose the interpreter that's executing a script? I have a script that I'm running on two different systems, and the interpreter I want to use is located in different ...
4
votes
2answers
3k views

Why am I able to pass arguments to /usr/bin/env in this case?

I read in another answer that I'm not able to pass arguments to the interpreter than I'm giving to /usr/bin/env: Another potential problem is that the #!/usr/bin/env trick doesn't let you pass ...