我有一个很长的Bash函数,在脚本中,可以使用多个stdin输入。接下来的是该功能的简短版本。
foobar(){
cat > tmp.sh
cp tmp.sh commands.sh
// and more scripts here
// something here to initialize stdin
. commands.sh
// and more scripts here
}
作为功能的用法,首先将命令列表发送到文件,然后将文件评估为命令列表。
下一个将成功,没有错误,但是下一个将失败,因为下一个需要确认y
为stdin。我知道您可以通过选项“ -y”绕过此确认,但是在这种情况下,我需要多功能性。
foobar <<< "echo baz"
foobar <<< "sudo apt-get install --install-recommends winehq-stable"
After this operation, 795 MB of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
因此该函数必须至少获取两个stdin,以任何方式实现此功能?谢谢。
答案 0 :(得分:0)
您可以将某些内容作为程序的输入:
foobar <<< "sudo apt-get install --install-recommends winehq-stable <<<\"y\""