0

When I run the bash command it opens a new subshell in the current directory. Is there a way to open the new bash shell in a different directory?

This is what it does:

$ pwd
/original/location
$ bash
$ pwd
/original/location

I'd like to do something like this

$ pwd
/original/location
$ bash "some magic command to start it in a /another/location"
$ pwd
/another/location
$ exit
$ pwd
/original/location

EDIT I also want it so that when I exit the subshell I return to the original location

jeffpkamp
  • 2,732
  • 2
  • 27
  • 51

1 Answers1

2

Simply cd to the directory before you start the subshell. To avoid changing directory in the parent shell, use parentheses to limit the change to a(nother) subshell:

(cd /another/location && bash)
Thomas
  • 174,939
  • 50
  • 355
  • 478