bash脚本监听键preSS继续前进 [英] Bash script listen for key press to move on

查看:182
本文介绍了bash脚本监听键preSS继续前进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我想编写一个bash脚本是一系列步骤和虐待确定为任务#。然而,每一步只完成,并且可以,只要用户想要运行

So, I want to write a bash script that are a sequence of steps and ill identify it as "task#". However, each step is only completed and can run as long as the user wants.

Do task1
if keypressed stop task1 and move on #this is the part I need help with. There can be up to 10 of these move on steps. 
Do task2
...

基纳像上面;它一直做的东西,直到你击中●要相当,但是,我想移动到接下来的事情

kina like top; it keeps doing stuff until you hit q to quite, however, i want to move on to the next thing

推荐答案

您可以使用与选项内置命令 -t -n

you can use read builtin command with option -t and -n

while :
do
    # TASK 1
    date
    read -t 1 -n 1 key

    if [[ $key = q ]]
    then
        break
    fi
done

# TASK 2
date +%s

这篇关于bash脚本监听键preSS继续前进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆