要实现Bash脚本不等待用户输入响应,可以使用以下两种方法:
#!/bin/bash
# 将文件作为输入流
./your_script.sh < input.txt
# your_script.sh是需要执行的脚本
# input.txt是包含所有用户输入的文件
#!/bin/bash
# 将命令的输出作为输入流
echo "user_input" | ./your_script.sh
# your_script.sh是需要执行的脚本
# echo "user_input"是将用户输入作为输出流的命令
这两种方法都可以将用户输入的内容通过文件或管道传递给脚本,从而避免脚本等待用户输入响应。
上一篇:bash脚本不等待用户输入