help-bash
[Top][All Lists]
Advanced

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

Re: default/simple globbing


From: lacsaP Patatetom
Subject: Re: default/simple globbing
Date: Fri, 29 Nov 2024 16:08:04 +0100

Le ven. 29 nov. 2024 à 03:40, Zachary Santer <zsanter@gmail.com> a écrit :

> On Wed, Nov 27, 2024 at 8:42 AM lacsaP Patatetom <patatetom@gmail.com>
> wrote:
> >
> > $ for usb in $(find /sys/bus/usb/devices/ | grep -E '/[0-9]+-[0-9]+$');
> do
>
> Please don't do this, even if you know no filenames you're expanding
> there contain whitespace. Develop good habits.
>
> > the goal is to use only `bash` and abandon `find` and `grep`
>
> But why?
>
> > (`find` can do this on its own).
>
> It sure can.
>
> shopt -s lastpipe
> find /sys/bus/usb/devices/ -regextype posix-extended -regex
> '/sys/bus/usb/devices/[[:digit:]]+(-[[:digit:]]+)*' -print0 |
>   while IFS='' read -r -d '' usb; do
>     printf '%s\n' "${usb}"
>     # etc.
>   done
> #
>

hi,

I didn't think this “simple” question would bring so many answers and
generate so much cross-referencing.
to be really precise, here's the code concerned by this globbing question :
https://github.com/patatetom/qemu-helpers/blob/2fd69ecccd86f1ac6566b4934682ba96e66ec390/.qemu-helpers.rc#L93
I finally opted for a substitution based on `find` and `grep` which (thanks
to the regular expression) avoids the possible presence of space(s) in the
name of the files found.

regards, lacsaP.


reply via email to

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