
次のbashコマンドセットを渡したい
{ echo Apple; echo Banana; }
.bashrc
bash関数のパラメータとして、次のように定義されます。
BashFunction(){
"$@" | SomeOtherFunction
}
BashFunction '{ echo Apple; echo Banana; }'
ただし、次のエラーが発生します。
{ echo Apple; echo Banana; }: command not found
Bash機能から引用符を削除すると、
BashFunction(){
$@ | SomeOtherFunction
}
これにより、このエラーが発生します。
{: command not found
答え1
配列を使うのはどうですか?
#! /bin/bash
myeval () {
for command in "$@" ; do
$command
done | other_func
}
myeval 'echo Apple' 'echo Banana'