Skip to content

is there a better way to complete only executables in a given dir #748

Answered by akinomyoga
calestyo asked this question in Q&A
Discussion options

You must be logged in to vote

This question is unrelated to bash-completion. This kind of question should be asked on the help-bash list.

I don't think there is a single command to obtain only the executable files. The suggested line can be rewritten in a more natural way as follows, but further improvements depend on the use case.

PATH=$PWD compgen -c | grep -vxF "$(compgen -abk -A function)"

Or rather than relying on hacks, files can be simply tested as

# Just for illustration of the idea, *not tested*
result=()
for file in "$someDir"/*; do
  if [[ -x $file ]]; then
    result+=("${file##*/}")
  fi
done

This is plain, clean, and flexible.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by calestyo
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants