sh 提示en bash。来自:http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 提示en bash。来自:http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell相关的知识,希望对你有一定的参考价值。

do_xxxx=n                      # In batch mode => Default is No
[[ -t 0 ]] &&                  # If tty => prompt the question
read -t 10 -n 1 -p $'\e[1;32m
Do xxxx? (Y/n)\e[0m ' do_xxxx  # Store the answer in $do_xxxx
if [[ $do_xxxx =~ ^(y|Y)$ ]]  # Do if 'y' or 'Y'
then
    xxxx
fi

# [[ -t 0 ]] && read ... => Lee solamente en TTY
# read -t 10 => Tiempo de espera de 10 segundos
# read -n 1 => Espera por un único caracter
# $'\e[1;32m ... \e[0m ' => Print in green
# (readable on both white/black backgrounds)
# [[ $do_xxxx =~ ^(y|Y|)$ ]] => bash regex

以上是关于sh 提示en bash。来自:http://stackoverflow.com/questions/226703/how-do-i-prompt-for-input-in-a-linux-shell的主要内容,如果未能解决你的问题,请参考以下文章

sh 来自http://ss64.com/bash/ls.html

sh Bash If语句示例 - 来自http://www.thegeekstuff.com/2010/06/bash-if-statement-examples

sh Bash - 时间戳功能示例 - 来自http://stackoverflow.com/questions/17066250/create-timestamp-variable-in-bash

sh Bash - 时间戳功能示例 - 来自http://stackoverflow.com/questions/17066250/create-timestamp-variable-in-bash

sh Bash - 样本If-Then - 来自http://tldp.org/LDP/abs/html/nestedifthen.html

sh Bash - 样本If-Then - 来自http://tldp.org/LDP/abs/html/nestedifthen.html