2

as I'm still a new Linux user, I still discover some behaviours and I'm unable to tell if they are "normals" or not. I searched the Internet but as I can't really find an answer I guess it's time to ask here.

Few weeks ago I installed a small game called "Machinarium" and I played it... but few days later when I wanted to continue my game I was unable to make the game start correctly. And as I didn't had the time to search I given up.

But yesterday as I was working on a program of mine, I had the exactly same behaviour. So I searched a bit and I discovered that when using Nautilus with the "List view", I was able to run the program (ie: the program does find the sound, images etc resources) when I was literally "inside" the executable folder, but unable when I was in a parent folder and expanding it to the executable folder to run it.

To illustrate the behaviour here are two screen shots.

  • It doesn't works if the executable is double clicked from here It doesn't works if the executable is started from here
  • It does works if the executable is double clicked from here It does works if the executable is started from here

This is indeed the same "place", but the Nautilus view is slightly different as the current folder is not the same and it seems to make a difference for the program.

Furthermore, when I create a menu items via System Settings/Main Menu to the executable, it behaves just like if the executable can't find the resources (that's why I was unable to play Machinarium the second time as I created a menu short-cut after my first game).

So I asked my program to generate a text file at it's root when running, and I started to launch it from different "parent" folders to see where is generated the text file. Each time the file was generated on the top folder of the current Nautilus view.

I was expected to see it appears in the same folder of the executable (well not as I was guessing what as happening, but before that I would have expected to see it appears in the exe folder).

  • Does anyone can explain me why it does works like this (I guess it's normal) ?
  • How I'm supposed to solve this when creating programs (Should I detect the executable path in my C++ code or should I organize the resources files another way than on windows ?)

2 Answers 2

3

There is a nice question here with answers to give you an idea where to install user applications.

To run an application the executable bit has to be set. This can also be done from Nautilus in the right click menu (Properties -> Permissions).

You can then run any executable binary or script by double-clicking in Nautilus or by running the following in a terminal (note the ./ run command):

./path/to/executable/application

If your application needs to be run in it's path, then you need to change the directory to this path first by executing:

cd /path/to/executable
./application

To ease this you can also create a Launcher to run the application (see e.g. this answer and many others)

This is how I have done it with Machinarium.

It is not recommended to put your own user custom files in /usr/bin. This directory may be overwritten in case you upgrade your system later and it usually is not included in backup solutions. Instead, create a new directory in your home directory: ~/bin. You need to re-login for this directory be recognized.

1
  • 2
    In windows, there is a %PATH% environment variable, directories are separated by a ;. In Ubuntu, the equivalent is $PATH in which directories are separated by a :. To add a new directory to the current one which should take precedence over old directories, put the next line in your ~/.profile: PATH=/full/path/to/your/bin-dir:$PATH
    – Lekensteyn
    Jun 22, 2011 at 7:45
1

Yes. the PATH contains the list of paths where the commands are searched when you type them. If you wish to execute a command not in the path you need to give a relative or absolute path (./file or bin/file for example).

This behavior is probably a bug. The application probably executes some files in one of its directores (bin/ for example) but assuming that is being executed from the machinarium root directory (calls bin/file assuming dir is in the current directory) so if you run it from another directory the file will not be found.

A workaround is to create a script in the PATH that enters the machinarium directory and then executes it.

#!/bin/bash
cd /path/to/machinarium
./machinarium-or-whatever

just name it machinarium and put it under a directory that is in your path (/usr/local/bin or one in your /home). You can run that command from any directory then.

2
  • I would upvote, if you remove the suggestion to put the script in /usr/bin.
    – enzotib
    Jun 22, 2011 at 7:58
  • you are right /usr/bin is not the place to put it. Jun 24, 2011 at 0:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .