Skip to main content

Pass a group of bash commands to bash function [Resolved]

I want to pass the following group of bash commands

{ echo Apple; echo Banana; }

as an argument to a bash function defined in .bashrc as follows:

"$@" | SomeOtherFunction
BashFunction '{ echo Apple; echo Banana; }'

But I get this error:

{ echo Apple; echo Banana; }: command not found

If I remove the quotes from the bash function

$@ | SomeOtherFunction

Then I get this error

{: command not found

Question Credit: Nikhil
Question Reference
Asked July 21, 2019
Posted Under: Unix Linux
1 Answers

What about using an array?

#! /bin/bash
myeval () {
    for command in "$@" ; do
    done | other_func

myeval 'echo Apple' 'echo Banana'

credit: choroba
Answered July 21, 2019
Your Answer