Way to use glob path pattern (asterisk) in $PATH

2021-04-29 Thu.

Definition of Environment Variable in Linux doesn’t expand glob pattern by default. But you might need expand glob pattern in your $PATH, in such case using IFS is one of way to resolve this problem.

1resolve_glob () {
2 local IFS=":"
3 echo "$*"
5export PATH=$PATH:`resolve_glob /path/to/glob/*.sh`

This will work.

If you are using zsh, anonymous function is useful. Script will be one-liner and not affect global namescope.

1IFS=":" export PATH=$PATH:`() { echo "$*"; } /path/to/glob/*.sh`

This works for /path/to/glob/*.sh glob pattern as above, and /glob/inside/*/path glob pattern also works.

Under Construction