Vipul Vipul - 4 months ago 27
Python Question

Executables in subfolder in path

I wish to place my executables in subfolders:

$ tree
├── bin
│   ├──
│   ├── method1
│   │   ├──
│   │   └──
│   └── method2
│   ├──
│   └──

If I include bin/ folder in PATH, is there a way to access executables from my shell script (which is in another directory), as e.g.

$ method1/ arg1 arg2

The above command gives an error (No such file or directory), but

$ arg1 arg2

works, as it is not in a subfolder.

Kindly advise how I can organise executable files in subfolders. Thanks.


As documented here the bash shell (and probably most other shells too) only looks for the command on the $PATH if the command name contains no slashes.

There are several ways you can solve the issue:

  1. You can make a folder containing symbolic links to the commands and add that folder to the $PATH.
  2. You can add the subfolders to the $PATH. If there are many subfloders you can do it automatically
  3. You can change the scripts current dirrectory to your bin. An easy way to temporarily change the current dirrectory is to use subhells.
  4. And of cource you can try using a different shell that does the command search differently. Sorry, but I don't know where to find one, you'll have to google this yourself if you really need it.