Sujet : Re: Create functional processing pipe (without eval)?
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shellDate : 07. May 2025, 16:07:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vvfsv4$138lg$1@dont-email.me>
References : 1 2
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 07.05.2025 14:58, Lars Poulsen wrote:
On 2025-05-07, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
I'm pondering about creating a functional processing pipe, depending
on program parameters, and whether that's possible to achieve without
using 'eval'.
>
Say, the program is called "filter" and may accept 0..N parameters and
depending on the set of parameters the respective pipe functionality
shall be defined like
>
filter => cat
filter p1 => cat | func p1
filter p1 p2 => cat | func p1 | func p2
filter p1 p2 ... pN => cat | func p1 | func p2 | ... | func pN
>
where "func" is working as filter and accepts exactly one parameter.
>
(Because of reservations I have with 'eval' and quoting I'd like to
avoid that 'eval' indirection if possible.)
For a limited number of arguments, you could do it with a switch,
enumerating the variations. I can see the utility of such a feature.
Well, for the application case I have in mind that would indeed be
possible; I expect not more than a handful of arguments in one call.
Only such hard coded solutions repel me; triggers some aesthetics
nerves badly.
It seems that you could do this with a small wrapper program (in your
favorite progframming language) activating the shell once the pipeline
has been constructed.
Well, yes. In an abstract thought that was the direction I was
thinking of, but I couldn't really wrap my head around it with
the tools I'm using. (I'd think with Lisp or other functional
languages you may get that out of the box, but I'm with Shell
and Awk at the moment.)
I would like to have this king of feature wrapped around grep in order
to do compounded keyword searches, but it's not a high priority.
I recall I've done such with 'grep', simply transforming the
shell arguments to a 'grep' argument. It was simple, like
x=$*
grep -E '('"${x// /|}"')'
(BTW, strangely, using "${*// /|}" straightly (without 'x')
doesn't seem to work for that.)
Janis
Lars