timeout.sh

来自「Shall高级编程」· Shell 代码 · 共 41 行

SH
41
字号
#!/bin/bash# timeout.sh#  Written by Stephane Chazelas,#+ and modified by the document author.INTERVAL=5                # timeout intervaltimedout_read() {  timeout=$1  varname=$2  old_tty_settings=`stty -g`  stty -icanon min 0 time ${timeout}0  eval read $varname      # or just  read $varname  stty "$old_tty_settings"  # See man page for "stty".}echo; echo -n "What's your name? Quick! "timedout_read $INTERVAL your_name#  This may not work on every terminal type.#  The maximum timeout depends on the terminal.#+ (it is often 25.5 seconds).echoif [ ! -z "$your_name" ]  # If name input before timeout...then  echo "Your name is $your_name."else  echo "Timed out."fiecho# The behavior of this script differs somewhat from "timed-input.sh".# At each keystroke, the counter resets.exit 0

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?