假设用户供给时间:验证用户反馈时间在bash与正则表达式模式
read -p "Enter the start time you want to start(hh:mm:ss) " user_start_time
和正则表达式:
timePattern="[0-2][0-3]:[0-5][0-9]:[0-5][0-9]"
如果我这样做:
if [ "$user_start_time" == "$timePattern" ]
#or if [ "$user_start_time" =~ "$timePattern" ]
then
echo "in if"
else
echo "in else"
fi
一点也没有”吨验证.....是新手,我明白比较int
或string
但我们如何去约time
(日期是有过,但date -d
解决了问题,很多)
There is this question too但不能理解接受的答案!
您的问题引号是用==''和'=〜''内[...]'。你需要使用双方括号。参考链接的问题。 – devnull
@devnull:是的,提到它的时刻,你张贴.... thankx队友! :) – NoobEditor
@devnull:一个简单的问题,如果我总是使用'[[''验证而不是'['只是为了更安全的一面? – NoobEditor