问题描述
我有一个 Bash 脚本,它按顺序运行一些从文件中读取的 Perl 脚本.这些脚本需要按 Enter 才能继续.
I'm having a Bash-Script that sequentially runs some Perl-Scripts which are read from a file. These scripts require the press of Enter to continue.
奇怪的是,当我运行脚本时,它从不等待输入,而是继续.我假设 Bash 脚本中的某些内容被解释为 Enter 或其他一些按键,并使 Perl 继续.
Strangely when I run the script it's never waiting for the input but just continues. I assume something in the Bash-Script is interpreted as an Enter or some other Key-Press and makes the Perl continue.
我确定有一个解决方案,但我真的不知道该寻找什么.
I'm sure there is a solution out there but don't really know what to look for.
我的 Bash 有这个 while-Loop,它遍历 Perl 脚本列表(在 seqfile
中列出)
My Bash has this while-Loop which iterates through the list of Perl-Scripts (which is listed in seqfile
)
while read zeile; do
if [[ ${datei:0:1} -ne 'p' ]]; then
datei=${zeile:8}
else
datei=$zeile
fi
case ${zeile: -3} in
".pl")
perl $datei #Here it just goes on...
#echo "Test 1"
#echo "Test 2"
;;
".pm")
echo $datei "is a Perl Module"
;;
*)
echo "Something elso"
;;
esac
done <<< $seqfile;
您注意到带有 echo "Test 1/2"
的两条注释行.我想知道它们是如何显示的.实际上,它们是相互书写的,就像有一个 Enter-Press:
You notice the two commented lines With echo "Test 1/2"
. I wanted to know how they are displayed.Actually they are written under each other like there was an Enter-Press:
Test 1
Test 2
Perl 脚本的输出是正确的,我只需要找出一种方法来强制从用户而不是从脚本中读取输入.
The output of the Perl-Scripts is correct I just have to figure out a way how to force the input to be read from the user and not from the script.
推荐答案
从 /dev/tty
获取 perl 脚本重定向输入.
Have the perl script redirect input from /dev/tty
.
概念证明:
while read line ; do
export line
perl -e 'print "Enter $ENV{line}: ";$y=<STDIN>;print "$ENV{line} is $y\n"' </dev/tty
done <<EOF
foo
bar
EOF
程序输出(粗体的用户输入):
Program output (user input in bold):
输入 foo:123foo 是 123
输入栏:456酒吧是 456
Enter foo: 123foo is 123
Enter bar: 456bar is 456
这篇关于强制 Bash 脚本等待等待输入的 Perl 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!