Tip: The $PATH not taken

This tip first appeared on  Betips.net  and has been updated to reflect the packaging system.

When you start working in Haiku, it is tempting to hit Beshare, FTP sites and the repositories and download everything in sight. A lot of command-line files can be found there from the BeOS days. But you might want to check if you don’t already have them.

Take  wget, for example: an excellent command-line utility that will reach out over the net and retrieve a file. You will find it on many legacy BeOS sites, and if you download it you should install it into /boot/home/config/non-packaged/bin.

But wait a minute! Haiku already has its own  wget, in /boot/system/bin. Now suppose you had both, which one would activate if you typed   wget  in the Terminal? That is easy to find out, just type the following command:

echo $PATH

and it will spit out a list of directories all ending with “bin” (for “binary”). Whenever you type a command in the Terminal, it will search those directories, in that exact order, for something to execute. On a typical system, /boot/home/config/non-packaged/bin/ always wins.

In fact, Haiku contains a lot of these command-line utilities that used to be separate downloads in BeOS. Now maybe the new one in /boot/home/config/non-packaged/bin really is more up-to-date, in which case you can just leave it alone. But will you remember to check after Haiku next receives an update? And there is a real possibility that you are using an out-of-date version.

So before you download and install anything for the Haiku command line, just open a Terminal and type that command to see if it isn’t there already.

Another way is to use the  which  command

which wget

will tell you where your instance(s) of  wget  can be located. Just keep in mind that  which  is a UNIX port that knows nothing much about Haiku. It takes a shortcut through the visible file system. which wget gives me /bin/wget to maintain POSIX compatibility, but as far as Tracker is concerned, that really is /boot/system/bin/wget. Those two really are the same file, and you can use either one in your scripts.