[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Detecting an opening { and a closing } in a variable
From: |
Lawrence Velázquez |
Subject: |
Re: Detecting an opening { and a closing } in a variable |
Date: |
Mon, 30 May 2022 15:23:04 -0400 |
User-agent: |
Cyrus-JMAP/3.7.0-alpha0-591-gfe6c3a2700-fm-20220427.001-gfe6c3a27 |
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