Git Product home page Git Product logo

Comments (11)

ndreas avatar ndreas commented on May 10, 2024 1

I also get this on Debian testing. It seems the -e argument to bash causes the shell to exit right away when an error occurs, which alternatively can be enabled using set -e when bash is started.

The solution is to replace

#!/usr/bin/env bash -e

with

#!/usr/bin/env bash
set -e

from rbenv.

josh avatar josh commented on May 10, 2024

Do you have bash on your machine?

from rbenv.

mhansen avatar mhansen commented on May 10, 2024

I also get this error, I have bash on my machine. Ubuntu 11.04.

The problem comes on line 8 of bin/rbenv, where it tries to cd into a directory called rbenv, which doesn't exist. I have no idea why it's trying to cd into a nonexistent dir.

Running bash under debug mode (with -x) shows this:

mark@mt~/.rbenv/bin> bash -x -e rbenv 
++ abs_dirname rbenv
+++ pwd
++ local cwd=/home/mark/.rbenv/bin
++ local path=rbenv
++ '[' -n rbenv ']'
++ cd rbenv
rbenv: line 8: cd: rbenv: Not a directory
[/snip/]

from rbenv.

gutenye avatar gutenye commented on May 10, 2024

I have the same problem.

#!/usr/bin/env bash -e

what's the -e option?. It seems linux's env doesn't support option in hashbang.

#!/usr/bin/env bash
# just use bash is fine.

#!/usr/bin/env ls -l
#=> /usr/bin/env: ls -l: No such file or directory

my platform is ArchLinux.

from rbenv.

mhansen avatar mhansen commented on May 10, 2024

the solution is to not cd into a directory that doesn't exist

from rbenv.

grahamedgecombe avatar grahamedgecombe commented on May 10, 2024

@mhansen: I think @ndreas' fix is also important - on my machine (Debian Squeeze), this does not work:

~% cat > test.sh
#!/usr/bin/env bash -e
echo "hello world"
~% chmod +x test.sh
~% ./test.sh 
/usr/bin/env: bash -e: No such file or directory
~% 

whereas the proposed alternative does:

~% cat > test.sh
#!/usr/bin/env bash
set -e
echo "hello world"
~% chmod +x test.sh
~% ./test.sh 
hello world
~% 

from rbenv.

mhansen avatar mhansen commented on May 10, 2024

Sorry, you're quite right. That's very confusing!

env is trying to run a file called bash -e, which it can't find anywhere in the path, instead of looking for a file called bash and passing -e as an argument.

$ env --version
env (GNU coreutils) 8.5

from rbenv.

telemachus avatar telemachus commented on May 10, 2024

Arguments on the shebang line are a known portability issue (see http://en.wikipedia.org/wiki/Shebang_(Unix)#Portability). Get enough people using something and the portability issues come out to play. But ndreas's fix should do the trick.

@mhansen I don't think the issue is env (its version or anything), but rather that different systems handle tokenizing the shebang line differently.

from rbenv.

josh avatar josh commented on May 10, 2024

#26

from rbenv.

donpdonp avatar donpdonp commented on May 10, 2024

Thanks for the fix! It works fine now. Its odd that the error only occurs when the script is executed from the command line.

$ bash --version
GNU bash, version 4.2.8(1)-release (i686-pc-linux-gnu)
$ cat a
#!/usr/bin/env bash -e
echo hello
$ ./a
/usr/bin/env: bash -e: No such file or directory
$ bash ./a
hello
$ 

from rbenv.

donpdonp avatar donpdonp commented on May 10, 2024

When I type
$ ./a

Its still bash doing the work there to interpret the script, right?

Oh hold the phone - thinking back to unix classes. Bash is doing a
fork() and linux is trying to interpret the executable.

Thanks for the note!

Don

On Fri, Aug 12, 2011 at 10:56 AM, grahamedgecombe
[email protected]
wrote:

@donpdonp, it's because, as mentioned earlier, when Linux parses the shebang line it doesn't split the arguments up, so it basically runs this:

   /usr/bin/env "bash -e"

Reply to this email directly or view it on GitHub:
#20 (comment)

from rbenv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.