if [ int1 -gt int2 ] 如果> if [ int1 -le int2 ] 如果<= if [ int1 -lt int2 ] 如果< 字符串变量表达式 If [ $a = $b ] 如果string1等于string2 字符串允许使用赋值号做等号 if [ $string1 != $string2 ] 如果string1不等于string2 if [ -n $string ] 如果string 非空(非0),返...
if[ $string1 !=$string2 ]如果string1不等于string2 if[ -n $string]如果string 非空(非0),返回0(true) if[ -z $string]如果string 为空 if[ $sting ]如果string 非空,返回0 (和-n类似) 条件表达式引用变量要带$ if [ a = b ] ;then echo equal else echo no equal fi [macg@machome ~...
elif [[ "$COMMAND" == "clear" ]]; then at -r $(atq | cut -f1) else echo "remind: unknown command $COMMAND. Type 'remind' without any parameters to see syntax." fi return fi # Determine time of notification if [[ "$OP" == "in" ]]; then local TIME="now + $WHEN" elif ...
then command command command else command command fi 條件運算式 if [ -f file ] 如果檔案存在 if [ -d ... ] 如果目錄存在 if [ -s file ] 如果檔案存在且非空 if [ -r file ] 如果檔案存在且可讀 if [ -w file ] 如果檔案存在且可寫 if [ -x file ] 如果...
每个if语句都要用fi结束,而且是每一个if都要对应一个fi。整个if语句用fi闭合起来才算完整,书写时if和fi要垂直对齐以方便查看。格式举例:if condition then command1 command2 fi condition是判断条件,如果 condition 成立(返回“真”),那么 then 后边的语句将会被执行;如果 condition 不成立(...
if 条件 then command1 else command2 fi 如果没写fi,报错信息: test.sh: line 14: syntax error: unexpected end of fi 1.2. 简练语法 条件&&命令 条件||命令 比如 [ -f "/etc/shadow" ] && echo "This computer uses shadow passwors"
elif [[ $1 = 'redis' ]] || [[ $1 = 'zookeeper' ]]; then echo "Input is $1"else echo "Input Is Error."fi 然而,初次尝试时,我们可能会误用为'else if',导致脚本执行出错。如在测试脚本中:bash [oracle@standby ~]$ ./ts01.sh zookeeper ./ts01.sh: line 12: syntax ...
Linux中if-else条件判断语句 在shell中的条件判断语句格式为: 代码语言:javascript 代码运行次数:0 复制 Cloud Studio代码运行 if[expression];then # 执行语句 elif # 执行语句else# 执行语句 fi 其中elif和else不是必须的,如果只需判断一次,那么if...fi即可。值得注意的是if后面中括号[]中的语句[的后面和]...
then echo "Input is $1"else echo "Input Is Error."fi 2.执行脚本,看脚本是否正常执行 [oracle@standby ~]$ ./ts01.sh zookeeper./ts01.sh: line 12: syntax error: unexpected end of file 备注:发现执行是错误的,经过查看可以知道,shell脚本中不是else if而是elif这个写法 3.修改脚本 #!/bin/...
if语句语法如下:if then 命令1 else 命令2 fi if语句的进阶用法:if条件1 then 命令1 elseif条件2 then 命令2 else 命令3 fi 举例说明if语句的用法,如下:#! /bin/bash if [ "10" -lt "12" ] then echo "10确实比12小" else echo "10不小于12" fi case语句语法如下:...