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, 23:55:31
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vvgod5$1a16t$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 07.05.2025 23:35, Christian Weisgerber wrote:
On 2025-05-07, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
function recurse
{
if [[ $# -ge 1 ]]
then grep "$1" | (shift; recurse "$@")
else cat
fi
}
>
I certainly need a "transparent" (idempotent) function if there are no
arguments provided, so a 'cat' is what I need in that case. (An empty
output would definitely be wrong for me.) And the unnecessary 'cat' at
the pipe end(s) is an acceptable unimportant degradation (for me). But
if you have an idea how to remove it... :-)
recurse()
{
case $# in
0) cat ;;
1) grep "$1" ;;
*) grep "$1" | (shift; recurse "$@") ;;
esac
}
Hah, simple and straightforward, that's great! 8-)
Thanks :-)
Janis