Bash script listen for key press to move on

后端 未结 2 406
别那么骄傲
别那么骄傲 2021-02-04 07:26

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.

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 07:42

    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
    

提交回复
热议问题