2021ๅนด1ๆ29ๆฅ(้) 13:43 Peng Yu <pengyu.ut@gmail.com>:
> I see that `compgen -f` shows not only files but also directories and
> fifo. Is there a way to just show files? Thanks.
No. If you are asking whether there is a way with a single call of
compgen without forks (as in your usual questions), the answer is no.
Of course, you can always use other commands, e.g., the `find' command:
$ find "$tmpdir" -maxdepth 1 -type f
If you want to process the generated filenames with compgen, you can
pass the result of `find' using the `-W' option:
$ IFS=$'\n' compgen $SOME_OPTIONS -W "$(find "$tmpdir" -maxdepth 1 -type f)"
Or, if you don't want to use external commands or don't like forks, of
course, you can write it in Bash script:
$ for file in "$tmpdir"/*; do [[ -f $file ]] && echo $file; done
--
Koichi