0

I want to install some tools in specific directory in install.shand call them in test.sh, so I add the path like this:

# part of install.sh
path_add()
{
    if [ -d "$1" ] && [ ":$PATH:" != *":$1:"* ]; then
        echo "add $1 to PATH"
        export PATH="$PATH:$1"
        echo $PATH
    else
        echo "$1 already existing in PATH"
    fi
}

the echo shows that the $1 has been added to $PATH, but when install.sh exit, the $PATH do not contain the specified path just added, how to add it permanently and can affect the continuing shell environment?

coanor
  • 3,746
  • 4
  • 50
  • 67

1 Answers1

0
# part of install.sh
path_add()
{
    if [ -d "$1" ] && [ ":$PATH:" != *":$1:"* ]; then
        echo "add $1 to PATH"

        #export PATH="$PATH:$1"
        # global
        echo "export PATH=$PATH:$1" >> /etc/profile
        # or local
        # echo "export PATH=$PATH:$1" >> ~/.profile

        echo $PATH
    else
        echo "$1 already existing in PATH"
    fi
}

/etc/profile - global system setting

~/.profile - per user settings

user3439968
  • 3,418
  • 1
  • 18
  • 15