从键盘bash脚本控制变量

时间:2014-04-07 10:18:25

标签: linux bash shell input scripting

我需要使用k和j键控制2个变量。现在,我有了这个解决方案

read -s -n 1 -t 0.1 keys
    if [[ "$keys" == k ]]; then
        wpm=$(($wpm+10)) 
            if [[ "$wpm" -gt 1000 ]]; then
            wpm=$(($wpm-10))
            fi
    fi
    if [[ "$keys" == j ]]; then
        wpm=$(($wpm-10)) 
            if [[ "$wpm" -lt 100 ]]; then
            wpm=$(($wpm+10))
            fi
    fi

它不优雅,它是故障。我知道有绑定命令,但我需要将此脚本提供给用户,我不确定他们是否会打扰源(解决“警告:行编辑未启用”命令。

还有其他方法吗?

1 个答案:

答案 0 :(得分:0)

  

难怪它出现故障 - 为什么要使用0.1秒超时? - suspectus

怀疑人问了一个好问题。 user3047492,只需删除-t 0.1(除非您有进一步的要求保持安静)。

相关问题