3.02 if与字符串表达式

if与字符串表达式 #

字符串表达式常见的有以下几种

表达式 含义
-z 字符串长度为0
-n 字符串长度不为0

脚本说明

#!/bin/bash

answer="wangteng"   
if [ -z "${answer}" ];then
    echo "there is no answer."
    exit 1
fi
if [ "$answer" == "ab" ];then
    echo "the answer is incorrect"
elif [ "$answer" == "cd" ];then
    echo "the answer is also incorrect."
elif [ "$answer" == "wangteng" ];then
    echo "the answer is correct."
else
    echo "the answer is unknown."
fi

⬅️上一页

下一页➡️

Calendar Apr 17, 2021
Edit Edit this page
本站总访问量:  次 您是本站第  位访问者