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:
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