Change the path variable of the parent shell in the shell script

I wanted to change the path environment variable in the shell script. The path variable must be changed after the shell script is executed.

+3
source share
2 answers

There are two ways that I know this. The first is to run the script in the context of the current shell with any of:

. myscript.sh
source myscript.sh

but it risks polluting the current shell with all sorts of things.

I would prefer a solution in which the amount of information leakage is minimal. This means that it still works as a subshell, but outputs a new path to the output of statndard:

PATH=$(myscript.sh)

This method is much better, since the path is the only thing that the subshell can affect, but you must be careful what this subshell produces.

+8

script .

. script.sh

source script.sh

script , .

script, .

: script ?

+1

Source: https://habr.com/ru/post/1773020/


All Articles