Mark Kahn Mark Kahn - 1 year ago 67
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
.
is
/path/to/some
. 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