help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to compgen only files?


From: Koichi Murase
Subject: Re: How to compgen only files?
Date: Fri, 29 Jan 2021 14:33:23 +0800

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]