Mark Kahn Mark Kahn - 2 years ago 90
Bash Question

How do I pass the current working directory to a subshell in a different working directory?

I effectively just want to write:

/path/to/some/command .

but that command needs the working directory set so I'm trying to do:

(cd /path/to/some && command .)

but now
. How do I reference the current directory instead?

Answer Source

You may use the env variable OLDPWD to retrieve the previous working directory.

(cd /path/to/some && command "$OLDPWD")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download