[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Adding option to select file types
From: |
Stefan Krusche |
Subject: |
Re: Adding option to select file types |
Date: |
Wed, 7 Jul 2021 14:28:28 +0200 |
User-agent: |
KMail/1.9.10 |
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]
"$dir" in the above example is the "starting-point" because none of the
options are applied. It is the root of the path that 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
- Adding option to select file types, (continued)
Adding option to select file types, lisa-asket, 2021/07/07
Re: Adding option to select file types,
Stefan Krusche <=