15

At the moment I am trying to add a path for ns-2 to my .bashrc file, I have installed the ns-allinone-2.34 but the command ns gives the result: command not found when entered into the shell.

Here is what my .bashrc file currently looks like, I edited it using gedit:

# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi


# User specific aliases and functions
export PATH=/home/michael/ns-allinone-2.34/bin/ns:/home/michael/ns-allinone-2.34/bin/nam:$PATH

Can someone please explain why this isn't working or what a possible solution may be? I am using fedora 17.

user1825241
  • 846
  • 4
  • 9
  • 17

2 Answers2

46

Also if you export path like this, you want to keep old PATH as well, therefore include it as well.

export PATH=$PATH:/home/michael/ns-allinone-2.34/bin/
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
user1830432
  • 680
  • 1
  • 5
  • 9
  • 1
    He did, it's at the end, just as it should be. – tripleee Nov 29 '12 at 19:25
  • 1
    Oh, you are right, I didn't scroll there and expected original PATH to be in the beginning... – user1830432 Nov 29 '12 at 22:12
  • what's the exact difference between this answer and the accepted one? I mean, what happens if "$PATH:" is not added before bin's path? – Cristian Todea Dec 02 '16 at 09:07
  • @Todea the path gets searched in the order given. So if you put the existing path at the end, any same-named executables will be called instead of the normal ones. This is not usually what you want, and becomes a security hole if the folder has weaker perms than the system command folders: someone can get you to run an arbitrary command just by creating a file in there called "ls". But then, we shouldn't be running exes from world-writable folders anyway :) So, it's handy when you want to override the default system commands, but aliases won't cut it. – Dewi Morgan Jun 10 '17 at 19:22
13

The PATH should contain the directory for the binaries, not the binaries themselves.

For example, in the above:

export PATH=/home/michael/ns-allinone-2.34/bin/ns:..

should actually be:

export PATH=/home/michael/ns-allinone-2.34/bin:...
CaptJak
  • 3,592
  • 1
  • 29
  • 50
Brian Agnew
  • 268,207
  • 37
  • 334
  • 440