Sample Header Ad - 728x90

bash/zsh hook - Add to PATH only if no matching file found

1 vote
1 answer
740 views
I am looking for a bash/zsh *hook*, that is invoked when a command is not found. Say I run some arbitrary executable: xyz foo --bar 1. say that bash/zsh cannot find the executable. 2. is there a way to handle "not found" and then load some libraries to the PATH dynamically after that? something like this: function xyz { if ! test -f xyz; then load_libs xyz fi command -v xyz; } something like this function, but it would be for unknown executables. So generically it would look something like: function on_not_found { if ! test -f "$1"; then load_libs "$1" fi command -v "$@"; }
Asked by Alexander Mills (10734 rep)
Feb 18, 2022, 07:21 PM
Last activity: Feb 21, 2022, 07:24 AM