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

nix-shell in shebang fails if script name has a space or other shell metacharacters #4229

Closed
lilyball opened this issue Nov 6, 2020 · 1 comment · Fixed by #4281
Closed
Labels

Comments

@lilyball
Copy link
Member

lilyball commented Nov 6, 2020

Describe the bug

If my script name has a space in it, using nix-shell as a shebang fails as it doesn't escape the space. This also happens if the name contains other shell metacharacters, such as foo{1,2}.sh, but a space is the most common way to reproduce this.

Steps To Reproduce

Create a new file named foo bar.sh with the contents:

#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash
echo test

Mark it as executable and then execute it (or just pass it to nix-shell directly).

Expected behavior

It should execute and echo test.

Actual behavior

> ./foo\ bar.sh
bash: ./foo: No such file or directory

nix-env --version output

nix-env (Nix) 2.3.7

@lilyball lilyball added the bug label Nov 6, 2020
@lilyball
Copy link
Member Author

This also happens if the script filename is fine but exists in a directory with such characters, and the script is executed using a path that includes the directory name.

edolstra pushed a commit that referenced this issue Jan 20, 2021
This prevents spaces or other metacharacters from causing nix-shell to
execute the wrong path.

Fixes #4229.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant