博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【shell】5 函数与流程控制
阅读量:2154 次
发布时间:2019-05-01

本文共 749 字,大约阅读时间需要 2 分钟。

函数定义

语法一:

函数名 () {           代码块           return N           }

语法二:

function 函数名 {                 代码块                 return N                 }

创建与执行函数

创建

执行

流程控制

if

if [ condition ]             #condition 值为true or false

   then                          #条件为真的时候执行
      commands             #代码块 一行或者多行代码
fi                                  #语句结束    

if else

if [ condition ]     

     then                           #条件为真
          commands1         #真  要执行代码块
else                                #条件为假
          commands2         #假   要执行的代码块
fi                 结束

if elif else

if [ condition 1]                         满足第一个条件

     then                                    真

            command1                 执行command1代码块

elif [ condition 2]                     满足第二个条件
     then                                  真

             commands2             执行command2代码块

else                                       如果条件都不满足

            commandsX             执行commandX代码块

fi                                           结束判断

if简写

if [ !test1 ]     then        echo 'test1 is null'fi简写为[!test1 ] && echo 'test1 is null'if [! test2 ]    then         echo 'test2 is null'else    echo 'test2!!'fi简写为[!test2] && echo 'test2 is null' || echo 'test2!!'

 

转载地址:http://vzxwb.baihongyu.com/

你可能感兴趣的文章
【LEETCODE】231-Power of Two
查看>>
【LEETCODE】172-Factorial Trailing Zeroes
查看>>
【LEETCODE】112-Path Sum
查看>>
【LEETCODE】9-Palindrome Number
查看>>
【极客学院】-python学习笔记-Python快速入门(面向对象-引入外部文件-Web2Py创建网站)
查看>>
【LEETCODE】190-Reverse Bits
查看>>
【LEETCODE】67-Add Binary
查看>>
【LEETCODE】7-Reverse Integer
查看>>
【LEETCODE】165-Compare Version Numbers
查看>>
【LEETCODE】299-Bulls and Cows
查看>>
【LEETCODE】223-Rectangle Area
查看>>
【LEETCODE】12-Integer to Roman
查看>>
【学习方法】如何分析源代码
查看>>
【LEETCODE】61- Rotate List [Python]
查看>>
【LEETCODE】143- Reorder List [Python]
查看>>
【LEETCODE】82- Remove Duplicates from Sorted List II [Python]
查看>>
【LEETCODE】86- Partition List [Python]
查看>>
【LEETCODE】147- Insertion Sort List [Python]
查看>>
【算法】- 动态规划的编织艺术
查看>>
用 TensorFlow 让你的机器人唱首原创给你听
查看>>