-1

I've written a small gradle-path utility:

#!/usr/bin/env sh
export PATH=$PATH:/cygdrive/c/Gradle/gradle-3.5/bin

But, when I call it from my shell, the PATH is not changed at the end.

The variable isn't set in the parent process if I understand correctly.

How to make that possible?

user3341592
  • 1,419
  • 1
  • 17
  • 36

1 Answers1

0

As chepner said -

Executing it in its own subshell (normally) with something like

gradle-path

will create a child process, set the PATH in that child's environment, then deconstruct that environment when the child exits, doing nothing in the parent process's memory.

To change the PATH in the caller you have to run it in the caller's environment - "source" it - like this:

. gradle-path

or this:

source gradle-path

Those will basically insert the commands from the listed file into the caller's parsing stream, as if they had been written there.

Paul Hodges
  • 13,382
  • 1
  • 17
  • 36
  • Now that you both explain that, I know that I knew / had to know that; though, this escaped me somehow. Thanks for clearly answering this! – user3341592 Nov 14 '18 at 19:31