bash脚本中的换行符解释
我编写了一个小脚本,模拟某人在屏幕上键入用户输入 只要没有新线,效果就很好。我似乎不知道如何修改我的脚本来实现这一点,我知道这必须很简单 如果有人有更好的脚本编写方法,我也愿意进行完整的重构bash脚本中的换行符解释,bash,newline,printf,Bash,Newline,Printf,我编写了一个小脚本,模拟某人在屏幕上键入用户输入 只要没有新线,效果就很好。我似乎不知道如何修改我的脚本来实现这一点,我知道这必须很简单 如果有人有更好的脚本编写方法,我也愿意进行完整的重构 #!/bin/bash #Displays input as if someone were typing it read the_input_line while [ -n "$the_input_line" ] do printf "%c" "$the
#!/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
您的代码只读取一行。这会在所有线路上循环
#!/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
您的代码只读取一行。这会在所有线路上循环
#!/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
我应该澄清一下——我认为是新线人物把事情搞砸了。如果你做一些类似的事情(这个程序被称为打字机):ls-la | typewriterI应该澄清一下——我认为是新行字符把它搞乱了。如果您执行类似(该程序称为打字机)的操作,它会在换行符上中断:ls-la | typewriteries。这太简单了。我尝试了很多奇怪的破解,但没想到会做这样的嵌套循环。很酷,谢谢你,伙计。这太简单了。我尝试了很多奇怪的破解,但没想到会做这样的嵌套循环。很酷,谢谢你,伙计。