LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-12-2009, 08:32 AM   #1
shojaru
LQ Newbie
 
Registered: Mar 2009
Distribution: Ubuntu 9.04
Posts: 25

Rep: Reputation: 15
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
 
Old 06-12-2009, 11:11 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
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".
 
Old 06-12-2009, 10:26 PM   #3
shojaru
LQ Newbie
 
Registered: Mar 2009
Distribution: Ubuntu 9.04
Posts: 25

Original Poster
Rep: Reputation: 15
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.
 
Old 06-13-2009, 07:55 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,353
Blog Entries: 55

Rep: Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541Reputation: 3541
Quote:
Originally Posted by shojaru View Post
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 View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Environment Variable linux_linux Linux - Newbie 4 03-20-2008 10:16 PM
Environment variable vedanu Programming 1 05-17-2007 07:20 AM
Environment variable.. manomohan Programming 1 02-26-2007 11:27 PM
environment variable gamor Linux - Newbie 4 04-30-2005 05:28 PM
Environment Variable salmanucit Linux - Software 2 07-21-2004 02:27 AM


All times are GMT -5. The time now is 01:20 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration