我写了一个小脚本,模拟某人在屏幕上输入用户输入。
只要没有换行符,它就会很好用。我似乎无法弄清楚如何改变我的脚本以使其工作,我知道它必须简单。
如果有人有更好的脚本编写方法,我也愿意进行彻底的重构。
#!/bin/bash
#Displays input as if someone were typing it
read the_input_line
while [ -n "$the_input_line" ]
do
printf "%c" "$the_input_line"
sleep .1
the_input_line=${the_input_line#?}
done
答案 0 :(得分:4)
您的代码只读一行。这会遍历所有行。
#!/bin/bash
#Displays input as if someone were typing it
while read the_input_line
do
while [ -n "$the_input_line" ]
do
printf "%c" "$the_input_line"
sleep .1
the_input_line=${the_input_line#?}
done
printf "\n"
done