linux 如何将输入自动传递给从父shell脚本调用的子shell脚本

bxfogqkk  于 2023-04-20  发布在  Linux
关注(0)|答案(1)|浏览(165)

我是shell脚本的新手,我有一个场景,我想把输入传递给一个shell脚本,从另一个shell脚本调用。
假设脚本1在执行时提示输入y或n

bash>./script1.sh
     Executing .....
     Do you want to continue (y/n)?

为了实现这一点,我已经把输入作为文件的一部分传递了,如下所示。

bash>./script1.sh < input.txt

类似地,如果有一个从www.example.com调用script2.shscript1.sh,我如何将input.txt传递给script2以提供输入?

./script1.sh < input.txt
r55awzrz

r55awzrz1#

子进程从父进程继承stdin/stdout/stderr,因此实际上,您不需要做任何事情。将“input.txt”作为stdin提供给父脚本“shell1.sh“将自动将该输入提供给从stdin阅读的任何子进程。
假设你没有重定向任何输入:所有内容(子进程或不子进程)都必须从控制台读取。

相关问题