Can anyone tell me how to add a directory, say Idl, which contains many sub-directories to my IDL_PATH in .bashrc such that when I do source .bashrc, I will be able to it is able to run all the executables inside all the different sub-directories?

Is this possible? I am doing

IDL_PATH=.:+/idl/idl70/lib:/home/cs/Idl .... 

The Idl folder has many sub-directories (eg. xidl, idl_code, net etc.). However, I am only able to run files in folder Idl, not those in sub-directories.

The files which I want to run are IDL procedures with .pro extensions. If I put my all .pro files into a single directory, say /home/cs/Idl, then my whole pro files are being run.

Is there any way?

  • Do you need to add the directories to IDL_PATH or PATH?
    – terdon
    Mar 20, 2016 at 14:08
  • Any thing either PATH or IDL_PATH its just a name to direct a particular path. Mar 20, 2016 at 14:14
  • Are you sure? It looks like IDL_PATH is a completely different thing and used by the idl library. Directories in your PATH are searched recursively, so subdirectories are added automatically. It looks like IDL_PATH doesn't work that way. What are you trying to do? Do you just want to be able to run programs in the Idl directory? If so, add Idl to PATH not IDL_PATH.
    – terdon
    Mar 20, 2016 at 14:19
  • No it is not running even with simple PATH option. I think it should be IDL_PATH. Mar 20, 2016 at 14:30
  • I want all the programs which are in various sub directories inside the main Idl directory to be run globally any where in the system. Mar 20, 2016 at 14:32

3 Answers 3


It looks like you will have to either add each directory that contains an executable separately or link all executables to the same directory.

  1. Add all directories manually.

    First, collect the list of relevant directories (I am assuming you are running Linux or, in any case, that you have GNU tools):

    find /home/cs/Id -type f -executable -exec dirname {} + | sort -u

    The above will find all executable files in /home/cs/Id and print the name of the directory containing them. The sort -u ensures that each directory is only printed once. I created a few test directories, so on my system I get:

    $ find /home/terdon/Idl/ -type f -executable -exec dirname {} + | sort -u

    Now, you want to get these into the right format for adding to $PATH:

    $ find /home/terdon/Idl/ -type f -executable -exec dirname {} + | sort -u | tr '\n' ':'

    Copy that (excluding the final :) and add it to your PATH:

  2. Find all executable files and symlink them to a directory already in your PATH.

    find /home/terdon/Idl/ -type f -executable -exec ln -s {} ~/bin \;

    On some Linux systems (Ubuntu, for example) the ~/bin directory is automatically added to your PATH if it exists. If this doesn't happen on your system, add it yourself:


I think one has to enumerate the directories, then. This generates the line for you automatically:

# -*- coding: utf-8 -*-

# Copyright © 2016 Martin Ueding <[email protected]>
# Licensed under the MIT license

import argparse
import os

def main():
    options = _parse_args()

    additions = []

    for base in options.base:
        for dirpath, dirnames, filenames in os.walk(base):

    line = ':'.join(additions)

    if options.short:

def _parse_args():
    parser = argparse.ArgumentParser(description='')
    parser.add_argument('base', nargs='+', help='Basepath')
    parser.add_argument('--short', action='store_true')
    options = parser.parse_args()

    return options

if __name__ == '__main__':

Save that snippet as /usr/bin/path-recurse and apply chmod +x /usr/bin/path-recurse. Then you can use it in your prompt either to generate the line with path-recurse /tmp /foobar … and it will give you the Bash line:


Alternatively you can use the following in your .bashrc:

PATH=$PATH:$(path-recurve /tmp /foobar …)

This will then dynamically go through all the folders whenever the .bashrc is sourced.


I think I have solved my problem. All I did in my .bashrc file I wrote:

PATH=${PATH}:$(find ~/Idl -type d | tr '\n' ':' | sed 's/:$//')

Then: > source .bashrc

Now I am able to run all programs and scripts inside various sub-directories under my main Idl directory.

Thanks all for your kind attentions.

You must log in to answer this question.

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