【发布时间】:2020-05-05 23:27:24
【问题描述】:
描述:我有一个脚本,它以向用户提出的警告/问题开头。我需要用户回答yes/y 或no/n。
问题:虽然我有一个条件来确保用户提供上面提供的以下答案之一,但我还需要确保用户只提供一个输入。我曾尝试使用
[ "$#" -eq 1 ] 或 [ $# -eq 1 ] 这些条件似乎都不能解决问题
这是我目前所拥有的:...
#!/bin/bash
#
# Descritpion: some Windows OS script
#
#
printf "(!)WARNING(!): 1. The this program is ONLY compatible with Windows operating systems. "
printf "2. You will NEED to be logged in as an ADMIN in order to fully make use of the '*****' script.\n"
printf "Would you like to continue? yes or no (y/n): "
#would it be cleaner to use "case" rather than a "while" w/ multiple conditionals? (01.19.2020)
read opt
while (true)
do
if [ $opt == yes ] || [ $opt == y ]
then
printf "continue. \n"
break
elif [ $opt == no ] || [ $opt == n ]
then
printf "OK, exiting the script! \n"
exit 0
#elif [ "$#" -ne 1 ]
#then
# "Too many arguments have been provided, please try again. \n"
# read opt
else
printf "The opition you provided is not recognized, please try again. \n"
read opt
fi
done
【问题讨论】:
-
only ONE input is provided by the use- 请举例说明应该发生什么。 “一个输入”是什么意思?什么是“双输入”?
标签: linux bash if-statement conditional-statements git-bash