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),返...
then 函数reture值0为真,走then echo " your answer is yes" else 函数return值非0为假,走else echo "your anser is no" fi if command 等价于 command+if $? ===以条件表达式作为 if条件=== 传统if 从句子——以条件表达式作为 if条件 if [ 条件表达式 ] then command command command else command ...
then 函数reture值0为真,走then echo " your answer is yes" else 函数return值非0为假,走else echo "your anser is no" fi if command 等价于 command+if $? ===以条件表达式作为 if条件=== 传统if 从句子——以条件表达式作为 if条件 if [ 条件表达式 ] then command command command else command ...
每个if语句都要用fi结束,而且是每一个if都要对应一个fi。整个if语句用fi闭合起来才算完整,书写时if和fi要垂直对齐以方便查看。格式举例:if condition then command1 command2 fi condition是判断条件,如果 condition 成立(返回“真”),那么 then 后边的语句将会被执行;如果 condition 不成立(...
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 ...
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/...
sh #!/bin/bash fail=0 while ((1==1)) do read -p "please enter you username: " user read -p "please enter you password: " password if [[ $user = 'guoke' && $password = 'guoke123' ]];then echo "login success" exit 1 else if [ $? -ne 0 ];then let fail=fail+1 #...
bashcheck_file_exists(){if[-f"$1"];then echo"文件存在"return0elseecho"文件不存在"return1fi} 设计异常的返回值 对于错误或异常情况,应使用非零值作为返回值。在 Shell 中,1-255的范围可用于表示不同类型的错误。通常,1用作通用错误代码,但您可以根据需要使用不同的值来表示特定类型的错误。
fi # Run commands: list, clear if [[ $COUNT -eq 1 ]]; then if [[ "$COMMAND" == "list" ]]; then at -l elif [[ "$COMMAND" == "clear" ]]; then at -r $(atq | cut -f1) else echo "remind: unknown command $COMMAND. Type 'remind' without any parameters to see syntax....
if COMMAND then EXPRESSIONS elif COMMAND then EXPRESSIONS else EXPRESSIONS fi This structure is far from a single line. Moreover, we can have many lines inEXPRESSIONS. On top of that, we can expandCOMMANDwith the()syntax, adding still more lines. Finally, there are the&∧||operators, enabli...