Is it possible to get, using Bash, a list of commands starting with a certain string?
I would like to get what is printed hitting <tab> twice after typing the start of the command and, for example, store it inside a variable.
相关问题
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- JQ: Select when attribute value exists in a bash a
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
JacobM's answer is great. For doing it manually, i would use something like this:
The test before the output makes sure only executable, regular files are shown. The above shows all commands starting with
mod
.Interesting, I didn't know about
compgen
. Here a script I've used to do it, which doesn't check for non-executables:Save that script somewhere in your
$PATH
(I named itfindcmd
),chmod u+w
it, and then use it just likegrep
, passing your favorite options and pattern: