To get bash completion candidates

Question: Question:

When I press the Tab key while using bash in an interactive environment, completion candidates are displayed in a list. Is it possible to get this from a shell script? That is, a function-like image given the current $PATH and $PWD (or other environment variables you may need) and the string you are typing, from which the candidates are returned as an array of strings. is.

Is it easy to say that it is close to file-name-all-completions in Emacs LISP?

If anyone knows, please.

Answer: Answer:

I referred to a similar question in SO.
shell –bash completion script to complete file path after certain commandline options –Stack Overflow

Isn't it compgen -f ?

bash-3.2$ bash --version
GNU bash, version 3.2.53(1)-release (x86_64-apple-darwin14)
Copyright (C) 2007 Free Software Foundation, Inc.
bash-3.2$ ls
bash-3.2$ touch foo bar baz
bash-3.2$ ls
bar     baz     foo
bash-3.2$ compgen -f
bash-3.2$ compgen -f ba
Scroll to Top