Closed. This question is off-topic. It is not currently accepting answers. Learn more。
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
去年关门了。
假设我有一个程序可以从控制台获取有关用户的信息。
现在如果我不想手动输入“Foo”和“Bar”,而是想从文件重定向输入。。。
inputfile.txt文件
这就是输出。。。
通过重定向,您看不到冒号后面输入了什么。有没有办法使输入在控制台上可见(如第一个示例)?
编辑:这基本上是同一个问题,这个线程问:
on-topic
但是我只发现了改变程序和添加函数
在这里你可以使用
当程序更改为
所以你可以测试这个解决方案,并希望是最好的。
想改进这个问题吗?Update the question所以堆栈溢出的值小于aa>。
去年关门了。
假设我有一个程序可以从控制台获取有关用户的信息。
$ ./program
Enter your name : Foo
Enter your phone number : Bar
Your name is Foo and phone number Bar.
现在如果我不想手动输入“Foo”和“Bar”,而是想从文件重定向输入。。。
inputfile.txt文件
Foo
Bar
这就是输出。。。
$ ./program < inputfile.txt
Enter your name :
Enter your phone number :
Your name is Foo and phone number Bar.
通过重定向,您看不到冒号后面输入了什么。有没有办法使输入在控制台上可见(如第一个示例)?
编辑:这基本上是同一个问题,这个线程问:
on-topic
但是我只发现了改变程序和添加函数
isatty
的建议,但是有没有改变现有程序的方法? 最佳答案
这取决于你的程序。我为这个节目找到了一个窍门
printf "%s : " "Enter your name"
read name
printf "%s : " "Enter your phone number"
read phone
echo "Your name is ${name} and phone number ${phone}"
在这里你可以使用
while read -r line; do
sleep 1
echo "${line}"
done < inputfile.txt | tee >(./program)
当程序更改为
read -p "Enter your name : " name
read -p "Enter your phone number : " phone
echo "Your name is ${name} and phone number ${phone}"
所以你可以测试这个解决方案,并希望是最好的。