shell study notes (4)

1. Function

Define, after references

function name ()

{

  Block

}

Note: function can be omitted.

Call: function name

1 #!/bin/bash
2 add()
3 {
4         echo $[$1+$2]
5 }
6 
7 add 1 2
8 add 3 4

 

The function can also be written to a separate file, and then you can call other scripts.

 # vim sum.sh

add()
{
        echo $[$1+$2]
        echo $[$1*$2]
}

# vim 1.sh

1 #!/bin/bash
2 . sum.sh
3 
4 add 1 2
5 add 3 4

 

Guess you like

Origin www.cnblogs.com/ybliu/p/11519651.html