Execute the "nano function.sh" command to create a new shell script file with the name "function.sh".
650) this.width=650; "class=" Exp-image-default "alt=" How to write Function "src=" in shell scripts http://f.hiphotos.baidu.com/exp/w=500/ Sign=7148a1e65adf8db1bc2e7c643923dddb/d000baa1cd11728b6a382c5cccfcc3cec3fd2cb2.jpg "style=" border:0px; "/>
Edit the newly created shell script file "function.sh". The function must be defined before use.
650) this.width=650; "class=" Exp-image-default "alt=" How to write Function "src=" in shell scripts http://d.hiphotos.baidu.com/exp/w=500/ Sign=5a0b357a5d82b2b7a79f39c401accb0a/95eef01f3a292df51bb1016bb8315c6034a8735a.jpg "style=" border:0px; "/>
The contents of the shell script are as follows:
#!/bin/bash
Add () {
sum_1=$1;
sum_2=$2;
sum= ' expr $sum _1 + $sum _2 ';
echo "The sum is ${sum}";
}
Add $ A
650) this.width=650; "class=" Exp-image-default "alt=" How to write Function "src=" in shell scripts http://c.hiphotos.baidu.com/exp/w=500/ Sign=7dcf946a46a7d933bfa8e4739d4ad194/dbb44aed2e738bd4c1601c4fa58b87d6277ff90f.jpg "style=" border:0px; "/>
Assign executable permissions to the newly created function.sh command "chmod 755 function.sh".
650) this.width=650; "class=" Exp-image-default "alt=" How to write Function "src=" in shell scripts http://d.hiphotos.baidu.com/exp/w=500/ Sign=fc00484931fae6cd0cb4ab613fb30f9e/3812b31bb051f819ed33aa34deb44aed2e73e7be.jpg "style=" border:0px; "/>
Use "./function.sh 1 2" to invoke the script and pass two numbers to the script.
650) this.width=650; "class=" Exp-image-default "alt=" How to write Function "src=" in shell scripts http://d.hiphotos.baidu.com/exp/w=500/ Sign=dc44388c791ed21b79c92ee59d6fddae/aec379310a55b319b0142b0b47a98226cefc17da.jpg "style=" border:0px; "/>
The result of executing the command is "the sum is 3".
650) this.width=650; "class=" Exp-image-default "alt=" How to write Function "src=" in shell scripts http://g.hiphotos.baidu.com/exp/w=500/ Sign=cc41cc41ddf9d72a1764101de42a282a/77094b36acaf2edd75c1e197891001e939019398.jpg "style=" border:0px; "/>
Writing functions in the shell