help-bash
[Top][All Lists]
Advanced

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

Re: default/simple globbing


From: Tapani Tarvainen
Subject: Re: default/simple globbing
Date: Wed, 27 Nov 2024 17:59:56 +0200

On Wed, Nov 27, 2024 at 02:41:45PM +0100, lacsaP Patatetom 
(patatetom@gmail.com) wrote:

> the expression should take place in a `for` loop to replace this one
> which works as expected :
 
> $ for usb in $(find /sys/bus/usb/devices/ | grep -E '/[0-9]+-[0-9]+$'); do
> echo $usb; etc...; done

> the goal is to use only `bash` and abandon `find` and `grep` (`find` can do
> this on its own).

One way to that without any bash-specific stuff like extglob is to
filter the undesired entries inside the loop, e.g.,

for usb in /sys/bus/usb/devices/[0-9]*-*
do
  case "$usb" in
    *[:.]*) continue;;
  esac
  echo "$usb"
  ...
done

No external commands, and it should work in any POSIX-compliant shell
(and some pre-POSIX ones, too).

-- 
Tapani Tarvainen



reply via email to

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