Questions tagged [shebang]
Use the tag /shebang if your question is about `#!`-string at the beginning of a script
126
questions
1
vote
0
answers
36
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 ...
0
votes
1
answer
76
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 ...
3
votes
1
answer
691
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 ...
5
votes
1
answer
694
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:
#!/...
2
votes
2
answers
80
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, ...
2
votes
1
answer
174
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:
...
1
vote
1
answer
61
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 ...
0
votes
3
answers
302
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 ...
1
vote
1
answer
147
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 &...
1
vote
0
answers
132
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 ...
7
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 ...
-1
votes
2
answers
176
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 ...
6
votes
1
answer
625
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 ...
3
votes
1
answer
405
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 ...
2
votes
3
answers
2k
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 ...
0
votes
2
answers
92
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
# ...
3
votes
2
answers
392
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 ...
14
votes
2
answers
11k
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
2
answers
610
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 ...
1
vote
1
answer
669
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
2
answers
140
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
1
answer
1k
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'...
5
votes
1
answer
10k
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
1
answer
135
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 ...
2
votes
2
answers
223
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
1
answer
191
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 ...
17
votes
1
answer
5k
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
1
answer
20k
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
0
answers
445
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
...
7
votes
1
answer
7k
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
1
answer
521
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
1
answer
778
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
2
answers
182
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 ...
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> ...
4
votes
3
answers
712
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
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 ...
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 #...
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.
...
1
vote
1
answer
238
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⚓...
0
votes
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, ...
3
votes
0
answers
431
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
2
answers
251
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
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
...
1
vote
0
answers
168
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
1
answer
584
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
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
...
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 ...
2
votes
2
answers
137
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
1
answer
481
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 ...
7
votes
2
answers
4k
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 -...