LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   editing library environment variable -- (https://www.linuxquestions.org/questions/linux-newbie-8/editing-library-environment-variable-732465/)

shojaru 06-12-2009 08:32 AM

editing library environment variable --
 
Dear all,
I am installing different version of ns2 in my machine, in different directories under the Home folder. Now that I need to append the library path into bashrc, I am totally confused. I have little idea about it, and saw post about conflicting the environment path and system crash.
My library path is like:
# LD_LIBRARY_PATH
OTCL_LIB=/home/shojaru/ns-allinone-2.28/otcl-1.9
NS2_LIB=/home/shojaru/ns-allinone-2.28/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
# TCL_LIBRARY
TCL_LIB=/home/shojaru/ns-allinone-2.28/tcl8.4.5/library
USR_LIB=/usr/lib
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
# PATH
XGRAPH=/home/shojaru/ns-allinone-2.28/bin:/home/shojaru/ns-allinone-2.28/tcl8.4.5/unix:/home/shojaru/ns-allinone-2.28/tk8.4.5/unix
NS=/home/shojaru/ns-allinone-2.28/ns-2.28/
NAM=/home/shojaru/ns-allinone-2.28/nam-1.11/
PATH=$PATH:$XGRAPH:$NS:$NAM


Now that I will add environment variable for another ns2, should I keep the above one and add another same block by only modifying the path to new ns2? Like:
# LD_LIBRARY_PATH
OTCL_LIB=/home/shojaru/new/ns-allinone-2.29/otcl-1.9
NS2_LIB=/home/shojaru/new/ns-allinone-2.29/lib
X11_LIB=/usr/X11R6/lib
USR_LOCAL_LIB=/usr/local/lib
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB

And keep both the two blocks in the bashrc?

Or, I have to append them in the existing path? Would anyone care to elaborate a little bit on this? Please?

Thank you very much for your kind attention and response :)

unSpawn 06-12-2009 11:11 AM

I don't use NS2 but I think it depends on how you usually switch things. Try adding this to your ~/.bashrc:
Code:

set_NS2_VER() {
# Setting the default NS2 version
NS2_VER="2.29"

# Getting the version from a file (echo "2.28" > ~/.ns2_version)
[ -f ~/.ns2_version ] && NS2_VER=$(cat ~/.ns2_version)

case "$1" in
        old|2.28) NS2_VER="2.28";;
        new|2.29) NS2_VER="2.29";;
        *) continue;;
esac

# The basename of your NS2 installs
NS2_BASE=/home/shojaru/ns-allinone

NS2_LIB=${NS2_BASE}-${NS2_VER}/lib
OTCL_LIB=${NS2_BASE}-${NS2_VER}/otcl-1.9
TCL_LIB=${NS2_BASE}-${NS2_VER}/tcl8.4.5/library
USR_LIB=/usr/lib
USR_LOCAL_LIB=/usr/local/lib
X11_LIB=/usr/X11R6/lib
XGRAPH=${NS2_BASE}-${NS2_VER}/bin:${NS2_BASE}-${NS2_VER}/tcl8.4.5/unix:${NS2_BASE}-${NS2_VER}/tk8.4.5/unix
NS=${NS2_BASE}-${NS2_VER}/ns-${NS2_VER}/
NAM=${NS2_BASE}-${NS2_VER}/nam-1.11/

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OTCL_LIB:$NS2_LIB:$X11_LIB:$USR_LOCAL_LIB
export TCL_LIBRARY=$TCL_LIB:$USR_LIB
export PATH=$PATH:$XGRAPH:$NS:$NAM
}

set_NS2_VER old

This should give you access to a function called "set_NS2_VER" which, on parsing your .bashrc, will first set a default version, then glean it from ~/.ns2_version if it exists or else if the function is called with an argument like "new", "old", "2.28" or "2.29", then export what's needed. Note your NS2 installs should use same level dir names like "/home/shojaru/ns-allinone-2.28" and "/home/shojaru/ns-allinone-2.29".

shojaru 06-12-2009 10:26 PM

Dear unSpawn,
I really cannot find the words to thank you, so much time u spent on writing the codes!!!
I wanted to ask another question. I run ns programs, by going to the specific directory and type in the terminal: ns example.tcl So now,if I edit the ~/.bashrc as above, would it be the same procedure as before? Like:
shojaru@ubuntu:~/ns-allinone-2.28/ns-2.28$ ns example.tcl
shojaru@ubuntu:~/ns-allinone-2.29/ns-2.29$ ns example.tcl

or, I would have to change the procedure ?

Another question is, since I have already installed 2.29 on a different level directory, would it work if I just copy the whole directory into another location?

Thank you very much once again for your kind attention.

unSpawn 06-13-2009 07:55 AM

Quote:

Originally Posted by shojaru (Post 3572350)
I run ns programs, by going to the specific directory and type in the terminal: ns example.tcl So now,if I edit the ~/.bashrc as above, would it be the same procedure as before?

Try 'set_NS2_VER old; cd ~/ns-allinone-2.28/ns-2.28; ns example.tcl' or 'set_NS2_VER 2.29; cd ~/ns-allinone-2.29/ns-2.29; ns example.tcl'


Quote:

Originally Posted by shojaru (Post 3572350)
since I have already installed 2.29 on a different level directory, would it work if I just copy the whole directory into another location?

I have no idea since I don't use NS2. You could always (make a backup and) try.


All times are GMT -5. The time now is 08:15 PM.