help-bash
[Top][All Lists]
Advanced

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

Re: default/simple globbing


From: Zachary Santer
Subject: Re: default/simple globbing
Date: Thu, 28 Nov 2024 21:40:30 -0500

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
#



reply via email to

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