Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I am creating one bash script name as pathsetup.sh. In that , I am trying to setup a path to my user profile. S my script content is as ...
  1. #1
    Just Joined!
    Join Date
    Dec 2008
    Posts
    3

    Not able to setup PATH using linux shell script?

    Hi,

    I am creating one bash script name as pathsetup.sh.

    In that , I am trying to setup a path to my user profile. S my script content is as follows,

    pathsetup.sh contains,

    #!/bin/bash

    MY_PATH=/home/arun/NS3/ns-3.9/build

    export PATH=$PATH:$MY_PATH
    echo "$PATH"

    If I run the script, when run time it shows the MY_PATH added to PATH.

    But, when I check it in terminal after run, it doesn't add the PATH.

    if I put echo $PATH in terminal, it show old path.

    How can I add path permanently to a user.

    I read, ~.bash_profile , we can add the path permanently for a user.

    But, I want to add MY_PATH for a specific time.
    I don't want any user change the file .bash_profile each time.

    Just running the pathsetup.sh script, MY_PATH should be added to the user PATH.

    Instead of .bash_profile, using shell script, can it possible to add path permenetly for a user.

    any suggestion for this.

    thank you,

    Arun

  2. #2
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    136
    When you run a script like './pathsetup.sh' the interpreter forks a new process, deriving environment variables. But when your process changes any variable - it affects only its own $PATH variable, not parent's $PATH. So you should execute `export $PATH` in parent bash process. If you still want do this trick, try to send a command to parent's STDIN.

  3. #3
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    136

    Post

    if you want to run your script in current interpreter process, use the special '.' command like:

    Code:
    $ . myscript.sh
    and commands from 'myscript.sh' will be executed by your interpreter, changing its environment variables.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...