Temporarily change current working directory in bash to run a command
Something like this should work:
sh -c 'cd /tmp && exec pwd'
bash has a builtin
pushd SOME_PATH
run_stuff
...
...
popd
You can run the cd
and the executable in a subshell by enclosing the command line in a pair of parentheses:
(cd SOME_PATH && exec_some_command)
Demo:
$ pwd
/home/abhijit
$ (cd /tmp && pwd) # directory changed in the subshell
/tmp
$ pwd # parent shell's pwd is still the same
/home/abhijit