>> 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 software
run time characteristics for this use case.
> For instance simply doing:
>
> names=$(echo *txt)
>
> involves a sub-process for the command substitution. Since it is echo,
> it could be optimized.
I hope so.
> I just checked though; …
Thanks for your interest.
> If the goal is to just dump the names on standard output without the
> directory prefix,
Something like that.
> it can be done like this:
>
> for name in dir/*txt ; do
> echo ${name#dir/}
> done
I would like to avoid such an operation “Remove matching prefix pattern”
generally.
If the desired file lists contain only basenames, extra prefixes do not need
to be deleted.
Regards,
Markus