help-bash
[Top][All Lists]
Advanced

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

Re: Detecting an opening { and a closing } in a variable


From: goncholden
Subject: Re: Detecting an opening { and a closing } in a variable
Date: Mon, 30 May 2022 21:49:29 +0000

------- Original Message -------
On Tuesday, May 31st, 2022 at 7:23 AM, Lawrence Velázquez <vq@larryv.me> wrote:


> On Mon, May 30, 2022, at 2:42 PM, goncholden wrote:
>
> > I do not know the details on code injection. Am using a function that
> > searches for a phrase using grep.
> >
> > local progl=( "\.{rc,.el,c,f}" )
> > local pextd=( "${progl[@]}" "\.{cp,cpp,f90,f95,f03,f08}" )
> >
> > local inclsf=()
> > for el in "${incl[@]}" ; do
> > case $el in
> > "progl") inclsf+=( "${progl[@]}" ) ;;
> > "pextd") inclsf+=( "${pextd[@]}" ) ;;
> > "typog") inclsf+=( "${typog[@]}" ) ;;
> > *) inclsf+=( "$el" ) ;;
> > esac
> > done
> >
> > if (( ${#incl[@]} > 0 )); then
> >
> > # Split INCL by field separator FS
> > for ext in "${inclsf[@]}"; do
> > [[ "$ext" =~ "{*}" ]] && echo "Detected {}"
> > s="$ext"
> > [[ (! -z "$fs") && ("$ext" == "$fs") ]] && s=${ext//"$fs"/" "}
> > for fltyp in $s; do
> > isufx+=( --include="$fltyp" )
> > done
> > done
> >
> > fi
> >
> > grep --null -r -l "${isufx[@]}" -e "$phrs" -- "${fdir[@]}"
>
>
> Why not just use brace expansion instead of trying to reimplement it?
>
> incl_args=(--include=\*.{rc,el,c,f,cp,cpp,f90,f95,f03,f08})
>
> grep "${incl_args[@]}" -- whatever
>
>
> --
> vq

Hi Lawrence,

Have done as fallows

    for ext in "${incl[@]}"; do

      if [[ "$ext" == "progl" ]]; then
        isufx+=( --include=\*.{rc,el,c,f} )
        continue
      fi

      s="$ext"
      [[ (! -z "$fs") && ("$ext" == *"$fs"*) ]] && s=${ext//"$fs"/" "}
      for fltyp in $s; do
        isufx+=( --include="$fltyp" )
      done
    done

    echo " isufx: ${isufx[*]}"

Using progl, I got

 incl: typog
 ext: typog
 isufx: --include=*.org --include=*.texi --include=*.tex

So, in actual fact, one gets an include declaration for each file type.






reply via email to

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