The right way to find system paths

Because BeOS may one day go multi-user, and because it’s possible for users to hack BeOS into custom configurations, and for a variety of other reasons, it’s a bad idea to hard-code system paths such as /boot/home or /boot/beos/bin. BeOS provides a mechanism that will identify the proper directory for any given purpose. These directories are stored in the Storage Kit, and can be located from the shell with the finddir command.
You’ll find a complete list of „magic names“ in the Global Constants and Defined Types section of the BeBook (see the „Directories“ section). For example, one of the defined names is „B_BEOS_SYSTEM_DIRECTORY“. If you open a Terminal and type:


the shell returns:


If you type:


the shell returns:


and so on. So the right way to find the user’s home directory from within a script would be something like:

UserHome=$(finddir B_USER_DIRECTORY)

The value of $UserHome on most systems will then be /boot/home, but the script won’t break in the future if things move around.



No comments so far.

(comments are closed)