[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: default/simple globbing
From: |
#!microsuxx |
Subject: |
Re: default/simple globbing |
Date: |
Thu, 28 Nov 2024 23:59:55 +0100 |
and i reccommend learning more ...
1. dev sys is space safe
2. look
~/tt $ ls
2-3 2-3.1 2-3:1.0 usb2
~/tt $ declare -a "arr=( $( ls --hide='*[:.]*' --hide='[!0-9]*'
--quoting-style=shell-escape-always ) )" ; declare -p arr
declare -a arr=([0]="2-3")
and...
~/tt $ cd ..
~ $ mkdir tt2
~ $ cd tt2
~/tt2 $ touch '$( ..' '$( echo foo )' '$( echo foo >&2 )' '{' $'\1\xff'
~/tt2 $ declare -a "arr=( $( ls --quoting-style=shell-escape-always ) )" ;
declare -p arr
declare -a arr=([0]=$'\001\377' [1]="\$( .." [2]="\$( echo foo )" [3]="\$(
echo foo >&2 )" [4]="{")
~/tt2 $
friendly greetings ++
On Thu, Nov 28, 2024, 10:12 PM Chris Elvidge <celvidge001@gmail.com> wrote:
> On 28/11/2024 at 20:48, #!microsuxx wrote:
> > for d in $( ls --hide='*[:.]*' --hide='[!0-9]*' /sys/bus/usb/devices/ ) ;
> > do echo "$d" ; done
>
> Parsing the output of ls is not recommended.
> See (for e.g.) Greg's wiki: https://mywiki.wooledge.org/ParsingLs
>
> >
> > On Thu, Nov 28, 2024, 9:15 PM Chris Elvidge <celvidge001@gmail.com>
> wrote:
> >
> >> On 28/11/2024 at 19:56, Lawrence Velázquez wrote:
> >>> On Thu, Nov 28, 2024, at 8:56 AM, Chris Elvidge wrote:
> >>>> ls --hide='*:*' --hide='*.*' -l /sys/bus/usb/devices/
> >>>
> >>> As mentioned in a subsequent message, OP was using ls as an example;
> >>> the actual context is generating filenames for a loop.
> >>>
> >>> (In general, I wish people would stop trying to "simplify" their
> >>> questions like this, but that's neither here nor there.)
> >>>
> >>
> >> If s/he wants to generate the filenames s/he should be using an array,
> >> surely?
> >> e.g. files=(/sys/bus/usb/devices/*)
> >> and then : for f in ${files[@]}; do check $f && dowhatever; done
> >>
> >> --
> >> Chris Elvidge
> >> England
> >>
> >>
> >>
> >
>
>
> --
> Chris Elvidge
> England
>
>
>
- Re: default/simple globbing, (continued)
Re: default/simple globbing, Tapani Tarvainen, 2024/11/27
Re: default/simple globbing, Chris Elvidge, 2024/11/28
Re: default/simple globbing, Greg Wooledge, 2024/11/28
Re: default/simple globbing, ikhxcsz7y xmbott, 2024/11/28