|
From: | Kaz Kylheku (Coreutils) |
Subject: | Re: Determination of file lists from selected folders without returning directory names |
Date: | Mon, 17 Jul 2017 14:23:13 -0700 |
User-agent: | Roundcube Webmail/0.9.2 |
On 17.07.2017 12:37, SF Markus Elfring wrote:
A corresponding result could be achieved by using a subshell (which I would like to avoid for this use case) for a command like “(cd ${my_dir} && ls *txt)”.If you want to capture these strings into a variable, you can't really avoid a sub-process.I looked at a programming interface like the function “opendir”.I imagine that there are more advanced possibilities to improve the softwarerun time characteristics for this use case.
Well, if it has to be fast, perhaps don't write the code in the shell language.
Even an interpreted scripting language that can do string handling without resorting to fork()-based command substitution will beat the shell at many
tasks.
it can be done like this: for name in dir/*txt ; do echo ${name#dir/} doneI would like to avoid such an operation “Remove matching prefix pattern” generally.If the desired file lists contain only basenames, extra prefixes do not needto be deleted.
I.e. we can use the basename function: for name in dir/*txt; do basename "$name" done prints the basenames of the matching files, one per line.
[Prev in Thread] | Current Thread | [Next in Thread] |