Skip to main content
added 127 characters in body
Source Link
l0b0
  • 53.6k
  • 48
  • 225
  • 398

A script is run in a subshell, which means it has its own $PWD. Once it exits you get the "old" $PWD. If you want to keep the $PWD you need to source (aka. .) the script instead of running it. This won't work in a Makefile, however, because each command is run in a separate subshell:

$ pwd
/home/user
$ cat test.sh
cd /
$ cat Makefile
test:
    . ./test.sh && pwd
    pwd
$ make test
. ./test.sh && pwd
/
pwd
/home/user

A script is run in a subshell, which means it has its own $PWD. Once it exits you get the "old" $PWD. If you want to keep the $PWD you need to source (aka. .) the script instead of running it. This won't work in a Makefile, however:

$ pwd
/home/user
$ cat test.sh
cd /
$ cat Makefile
test:
    . ./test.sh && pwd
    pwd

A script is run in a subshell, which means it has its own $PWD. Once it exits you get the "old" $PWD. If you want to keep the $PWD you need to source (aka. .) the script instead of running it. This won't work in a Makefile, however, because each command is run in a separate subshell:

$ pwd
/home/user
$ cat test.sh
cd /
$ cat Makefile
test:
    . ./test.sh && pwd
    pwd
$ make test
. ./test.sh && pwd
/
pwd
/home/user
Source Link
l0b0
  • 53.6k
  • 48
  • 225
  • 398

A script is run in a subshell, which means it has its own $PWD. Once it exits you get the "old" $PWD. If you want to keep the $PWD you need to source (aka. .) the script instead of running it. This won't work in a Makefile, however:

$ pwd
/home/user
$ cat test.sh
cd /
$ cat Makefile
test:
    . ./test.sh && pwd
    pwd