这是出于学习目的.我写了一个模拟打字的脚本.
用法是:
$ typewriter (insert some text here)
Run Code Online (Sandbox Code Playgroud)
然后脚本将以随机的方式回显它,看起来像是在打字.很好,但问题是,如果输入包含分号(;)它会中断.
例如:
$ typewriter hello; world
Run Code Online (Sandbox Code Playgroud)
我想这是一个简单的修复.我只是想不出来.
提前致谢!
码:
#!/bin/bash
#Displays input as if someone were typing it
RANGE=4
the_input=$*
if [ x$* = "x" ] || [ x$* = "xusage" ] || [ x$* = "xhelp" ] || [ x$* = "x--help" ];
then
echo "Usage: typewriter <some text that you want to look like it's typed>"
exit 1
fi
while [ -n "$the_input" ]
do
number=$RANDOM
let "number %= RANGE"
printf "%c" "$the_input"
sleep .$number
the_input=${the_input#?}
done
printf "\n"
Run Code Online (Sandbox Code Playgroud)
不是真的:;表示命令的结束.你必须用管道和输入/输出重定向(一个类似的问题|,<,>),有意义的符号.
你唯一的选择是将参数放在引号中.
typewriter "some; text<>| that should be displayed"
Run Code Online (Sandbox Code Playgroud)