Choose or automatic continue

From WickyWiki
Revision as of 14:10, 1 March 2019 by Wilbert (talk | contribs) (Created page with "Category:Ubuntu Category:Bash Category:2019023 <syntaxhighlight lang=bash> # usage: choose_or_continue "question-without-questionmark" "default-answer" "secs-to-w...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


# usage: choose_or_continue "question-without-questionmark" "default-answer" "secs-to-wait"
function choose_or_continue {
  question=$1
  default=$2
  secs=$(($3))
  while [ $secs -gt 0 ]; do
    echo -ne "\r$question [$default]? $secs\033[0K"
    if read -s -n1 -t1 decide; then
      break
    fi
    let secs--
  done
  if [ -z "${decide}" ] ; then
    decide=$default
  fi
  echo -e "\r$question [$default]? $decide  "
}

choose_or_continue "Just do it" "n" "10"