Linux USES function instance details in the Shell script

  • 2020-06-07 05:59:34
  • OfStack

Linux USES function instance details in Shell scripts

A function of Shell

The Shell program also supports functions. A function that performs a specific function can be called repeatedly.

The function format is as follows:

 The function name ()
   The body of the function 

Function call method:

Function name argument list

Example: Write 1 function add to find the sum of two Numbers, the two Numbers passed by position parameters, the final output result.

root@ubuntu:/home/study# vi test3 

  z=`expr $a + $b`;
  echo "The sum is $z";
add $1 $2

root@ubuntu:/home/study# chmod +x test3
root@ubuntu:/home/study# ./test3 1 2

Thank you for reading, I hope to help you, thank you for your support to this site!

Related articles: