help-bash
[Top][All Lists]
Advanced

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

Adding option to select file types


From: lisa-asket
Subject: Adding option to select file types
Date: Wed, 7 Jul 2021 23:38:16 +0200 (CEST)

From: Stefan Krusche <epost@stefan-krusche.de>
To: help-bash@gnu.org
Subject: Re: Adding option to select file types
Date: 07/07/2021 12:38:49 Europe/Paris

Am Mittwoch, 7. Juli 2021 schrieb lisa-asket@perso.be:
> print-region ()
> {
> if (($# < 3)); then
> echo "usage: print-region startline endline startdir [extension ...]"
> >&2 echo "If extensions are not provided, .org and .texi will be
> used." >&2 return 1
> fi
>
> local na=$1
> local nb=$2
> local dir=$3
> shift 3
>
> if (($# == 0)); then
> set -- .org .texi
> fi
>
> # Construct find arguments dynamically from the extension list.
> local findargs=( "$dir" '(' )
> local ext
> for ext in "$@"; do
> findargs+=( -name "*$ext" -o )
> done
> # Overwrite the final -o with ')'
> findargs[${#findargs[@]}-1]=')'
>
> find "${findargs[@]}" \
>    -exec awk -v a="$na" -v b="$nb" '
>      FNR == 1 {s="\n==> "FILENAME" <==\n"; f = 0}
>      FNR == a {print s; f = 1}
>      f {print; if (FNR == b) nextfile}
> ' {} +
> }
>
> I cannot understand on mhy you use "$dir"

Because of the syntax of command "find" which can be peculiar:





- I understand it now, thank you.





SYNOPSIS
find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...]
[expression]

That's "starting-point". It is the root of the path find shall look in 
and has to be the first argument if you do not use one of the options. 
everything else is part of "expression" which contains normally the 
tests you do on the files.

HTH

Kind regards, Stefan





reply via email to

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