Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bash -e: No such file or directory #20

Closed
donpdonp opened this issue Aug 12, 2011 · 11 comments
Closed

bash -e: No such file or directory #20

donpdonp opened this issue Aug 12, 2011 · 11 comments

Comments

@donpdonp
Copy link

i just cloned the project and added the bin path to PATH, but get an error from env.

$ rbenv
/usr/bin/env: bash -e: No such file or directory
$ head -1 .rbenv/bin/rbenv

!/usr/bin/env bash -e

$ env bash -e
$

@josh
Copy link
Contributor

josh commented Aug 12, 2011

Do you have bash on your machine?

@mhansen
Copy link

mhansen commented Aug 12, 2011

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/]

@gutenye
Copy link
Contributor

gutenye commented Aug 12, 2011

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.

@ndreas
Copy link
Contributor

ndreas commented Aug 12, 2011

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

@mhansen
Copy link

mhansen commented Aug 12, 2011

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

@grahamedgecombe
Copy link

@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
~% 

@mhansen
Copy link

mhansen commented Aug 12, 2011

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

@telemachus
Copy link
Contributor

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.

@josh
Copy link
Contributor

josh commented Aug 12, 2011

#26

@josh josh closed this as completed Aug 12, 2011
@donpdonp
Copy link
Author

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
$ 

@donpdonp
Copy link
Author

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
reply@reply.github.com
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)

djmaze added a commit to hypriot/image-builder-odroid-c1 that referenced this issue Jan 17, 2016
The script wouldn't work as expected every time for me.

See e.g. this comment for some background for this change:
rbenv/rbenv#20 (comment)
djmaze added a commit to djmaze/os-rootfs that referenced this issue Jan 17, 2016
The `-e` wouldn't work as expected for me.

See e.g. this comment for some background for this change:
rbenv/rbenv#20 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants