Parent folder contains, many sub-folders (say in a few hundreds) containing executables or source programs. Say, parent folder, bin contains many sub-folders, mod1, mod2, ... modn (for example, /opt/app1/bin/ with sub-folders mod1, mod2, mod3, ...., modn). Adding all them to path variable may exceed the path character/line limit or could be very clumsy!

It is understood from dogbane's answer at what is wild card to select all directories in a directory that:
a) wild card */ can be used to match directories and
b) wild card **/*/ can be used to match directories and sub-directories.

Whether adding entry /opt/app1/bin/**/*/ to PATH variable, will search the executables in the sub-folders? Will there be any complications, by doing so?

  • Note that $PATH must be a :-delimited list of directory paths. A shell glob won't expand (directly) into such a list. – Kusalananda Mar 6 at 12:24
  • In what way are you adding /opt/app1/bin/**/*/ to the PATH? As that explicit string, or in the context of a wildcard expansion? Just so we focus on the right thing in this question. – Jeff Schaller Mar 6 at 12:50
  • the context is wild card expansion. ie. whould search in all the sub-directories. – AVA Mar 6 at 12:56
  • 1
    The more correct solution is to link (ln) all executables into one folder – user1133275 Mar 6 at 13:05

Yes, adding the expansion of /opt/app1/bin/**/*/ to the PATH variable (assuming you've set corresponding option for your shell to cause ** to expand) will cause executables to be searched for in those directories.

Note that the trailing */ is extraneous here; you can simply use the expansion of /opt/app1/bin/**/ to get the list of all subdirectories under /opt/app1/bin.

I do not see a length limitation in the POSIX specification for $PATH, given in Base Definitions -- Environment Variables -- Other Environment Variables.

The complications I can imagine are:

  • masking of identical commands -- given two identical executable names, the one that's found (and inserted into PATH) first will be the one that's called by default

  • additional delay when failing to find an errant command (as your shell searches all of those directories for it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.