Linked Questions

41 votes
2 answers
49k views

What is the difference if I start bash with "/bin/bash" or "/usr/bin/env bash"? [duplicate]

In shell scripts one specifies language interpreter on shebang(#!) line. As far as I know, it is recommended to use #!/usr/bin/env bash because env is always located in /usr/bin directory while ...
user avatar
  • 6,378
14 votes
2 answers
8k views

shell script header for best compatibility [duplicate]

Which one is better: #!/usr/bin/env sh #!/bin/sh empty/no header I used to think the 1st one is the best, anyway i've found on some Linux-based systems (like Android) that pathname is missing, so ...
user avatar
  • 1,435
0 votes
1 answer
549 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 /...
user avatar
  • 2,643
3 votes
0 answers
779 views

#! /bin/bash or #! /usr/bin/env bash? [duplicate]

I'm trying to write some provisioning shell scripts for Vagrant dev environment. I'm used to start bash scripts as follows #! /bin/bash But after surfing through some git repos I found out that in ...
user avatar
  • 1,828
0 votes
1 answer
248 views

What's the purpose of having "env [shell]" as an interpreter? [duplicate]

I already stumbled over #!/usr/bin/env bash on numerous occasions and never questioned it. Now, I'm wondering what the purpose of wrapping the shell interpreter in an env command, i.e. why not just ...
user avatar
53 votes
6 answers
7k views

Is there any reason to have a shebang pointing at /bin/sh rather than /bin/bash?

In most shell scripts I've seen (besides ones I haven't written myself), I noticed that the shebang is set to #!/bin/sh. This doesn't really surprise me on older scripts, but it's there on fairly new ...
user avatar
  • 1,944
76 votes
3 answers
48k views

How does /usr/bin/env know which program to use?

When I use the shebang #!/usr/bin/env python to run a script, how does the system know which python to use? if I look for a python bin path in the environment variables I find nothing. env | grep -i ...
user avatar
  • 1,105
20 votes
5 answers
11k views

How can I have more than one possibility in a script's shebang line?

I'm in a bit of an interesting situation where I have a Python script that can theoretically be run by a variety of users with a variety of environments (and PATHs) and on a variety of Linux systems. ...
user avatar
26 votes
3 answers
5k views

Why not use pathless shebangs?

Is it possible to have a shebang that, instead of specifying a path to an interpreter, it has the name of the interpreter, and lets the shell find it through $PATH? If not, is there a reason why?
user avatar
12 votes
4 answers
3k views

Distributing a script: Should I use /bin/gawk or /usr/bin/gawk for shebang?

Is gawk in /bin or /usr/bin usually? I would go with #!/usr/bin/env gawk but then I can't use arguments. Right now I'm using #!/bin/gawk -f. The script is very long and contains a lot of single ...
user avatar
17 votes
5 answers
6k views

How to start a script with clean environment?

I tried the following but it doesn't seem to work: $ cat script.sh #!/bin/env -i /bin/sh /bin/env $ script.sh /bin/env: invalid option -- ' ' Try `/bin/env --help' for more information.
user avatar
  • 4,049
7 votes
3 answers
14k views

Bash script command line argument to upper case

If I can do this in my bash shell: $ STRING="A String" $ echo ${STRING^^} A STRING How can I change my command line argument to upper case? I tried: GUARD=${1^^} This line produces Bad ...
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
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
7 votes
2 answers
5k 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 ...
user avatar
  • 2,566

15 30 50 per page