I have a bunch of apps installed locally in my home directory. In order for them to be globally available I add them to PATH in .bashrc:


How can I set it up so that I don't have to add each new one? I'm trying this but it's not working:


NOTE: I'm aware I can add them with a loop, but I'm also concerned my PATH variable will become too large, I'm wondering if it is possible to wildcard it somehow.

  • 1
    Presumably they have unique names, in which case you could symlink them to a (e.g.) /home/user/apps/all-apps/ directory and just add that one directory?
    – Jeff Schaller
    Jan 10 at 19:28
  • @JeffSchaller that's probably what I'll end up doing if wildcard is not possible, but is a little bit of extra work that I'd happily avoid.
    – php_nub_qq
    Jan 10 at 19:31

1 Answer 1


Wildcards will not be expanded in $PATH, no. Per the bash manual, PATH is:

A colon-separated list of directories in which the shell looks for commands

(my emphasis).

Coming from another direction, the Command Search and Execution section of the manual says, in part:

If the name is neither a shell function nor a builtin, and contains no slashes, Bash searches each element of $PATH for a directory containing an executable file by that name.

... (my emphasis) -- which makes no mention of any special processing done on the path elements, only that they are expected to be directories (as-is).

I'm not sure off-hand what the limit is for the size of a bash variable; I suspect it's available memory. PATH doesn't need to be exported, but many people do; if it is exported, it will need to fit along with other environment variables and arguments into getconf ARG_MAX (ref: https://unix.stackexchange.com/a/124422/117549). A large PATH directory should not induce too much of a performance overhead, since bash uses a hash table to remember locations of previously-found commands (per-session).

If you do hit a limit (visual or technical) with adding each individual application directory to your PATH, I would recommend adding one "symlink" directory to your PATH where you then link in the desired executables from the various applications.

  • 2
    PATH needs to be exported if you want child processes to see it. E.g. if want scripts to be able to find the stuff in /home/user/apps/app1/bin, too, or if you launch some other program from an editor, or from less etc. The default $PATH that Bash sets on my Debian looks to be /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:., which works for most things, but it's not the same as what I've set in the shell's startup files. Also the . at the end is somewhat interesting.
    – ilkkachu
    Jan 10 at 21:07
  • @ilkkachu if that does what I think it does then what happens if there's a file called cd in your directory :P
    – php_nub_qq
    Jan 11 at 6:49
  • 1
    @php_nub_qq, nothing much, since the cd builtin gets run first. And since . was last there, even if it was ls, it would be found in the dirs earlier in PATH. But if you mistype that as lss or sl, then the lookup would go to the end...
    – ilkkachu
    Jan 11 at 7:39

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.