我有以下bash脚本: # do some time consuming task here read -p "Give me some input: " input 现在您可能已经猜到,如果用户在“耗时任务”期间按下某些随机密钥,则也会考虑不需要的输入。stdin在发出read命令之前,如何清除(或至少忽略它)?
我比较了unix here-strings和pipe数据输入的执行时间 bc: 管 time for i in {1..1000} do echo "sqrt(5.09)" | bc -q > /dev/null done real 0m3.584s user 0m0.899s sys 0m2.404s VS 这里串 time for i in {1..1000} do bc -q <<< "sqrt(5.09)" > /dev/null done real 0m5.137s user 0m0.686s sys 0m2.262s (这些值是平均值:多次测试) 所以 real 使用here-strings的执行时间比使用管道更大 但总和 …
当我将postscript数据传输到gs程序中时,gs解释数据然后立即退出。这与手册页匹配: - This is not really a switch, but indicates to Ghostscript that standard input is coming from a file or a pipe and not interac- tively from the command line. Ghostscript reads from standard input until it reaches end-of-file, executing it like any other file, and then continues with …