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

Question: Why is PWD ignored when using devbox run? #2559

Open
alezkv opened this issue Mar 13, 2025 · 3 comments
Open

Question: Why is PWD ignored when using devbox run? #2559

alezkv opened this issue Mar 13, 2025 · 3 comments

Comments

@alezkv
Copy link

alezkv commented Mar 13, 2025

I am wondering if there is a specific reason why devbox run overwrites the present working directory (PWD) to the project root instead of respecting the current working directory.

Current behavior:

$ cd project
$ pwd
/user/project
$ cd subdir
$ pwd
/user/project/subdir
$ devbox run -- pwd
/user/project

Expected behavior (last command executed from the current directory):

$ devbox run -- pwd
/user/project/subdir
@apgrucza
Copy link
Contributor

I think it's because if you have scripts defined in devbox.json (which are executed by devbox run), you would want them to always run from the same directory.

But when you're using devbox run to run a command rather than a script, I agree it would be better to respect the current working directory.

@mohsenari
Copy link
Collaborator

Hey @alezkv when you run any devbox command including devbox run we always search for the first devbox.json we see going from the current directory up. Once we locate the devbox.json then the commands are run from the perspective of the json file. I agree that in your example it is a bit confusing to see pwd printing the location to the devbox.json rather than where the command is being run from. But overall, this approach helps having a consistent behavior among the 2 methods you can use devbox run :

  1. defining a script in devbox.json
  2. running a script with devbox run -- command

@alezkv
Copy link
Author

alezkv commented Mar 16, 2025

It appears that neither of these cases provides a proper way to execute a command within a subdirectory. With both approaches, I have to wrap the command with cd to meet my needs.

It would be great to see a hint for that behavior somewhere in the --help section.

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

No branches or pull requests

3 participants