0

I expected that

compgen -A file -G './tmp/*.sh'

would show only files under tmp/, but it also showed all files in the current directory.

I have tried

compgen -A file -X  '!(tmp/*.sh)'

and

compgen -A file -X  "!(tmp/*.sh)"

but both result in null output. Checking settings:

$ shopt|grep extglob
extglob         on

It's also worth noting that

compgen -A file tmp/*.sh

returns only the first valid candidate. Incidentally, this exactly matches the default line completion result, e.g.

cp tmp/*.sh[TAB]

and

ls tmp/*.sh[TAB]

both expand out to only the first candidate.

Two questions:

  1. Why?
  2. Any way to get the expected result using only compgen?

The 'expected result' is for all the matching candidates to be returned, as would happen with ls tmp/*.sh

Craig Hicks
  • 644
  • 8
  • 13

1 Answers1

0

@KamilMaciorowski's comment gave the answer.

My mistake was assuming that '-A file' was required when dealing with filenames. Using only -G 'tmp/*.sh will give the desired result.

The mistaken assumption resulted from there being many -A options, e.g. file, host, etc. However, when -G is used, the domain being filenames is implicit because globs only work with filenames.

Craig Hicks
  • 644
  • 8
  • 13