歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Shell編程學習之函數

Shell編程學習之函數

日期:2017/3/1 10:22:15   编辑:SHELL編程

shell編程學習之函數

1、創建函數和使用函數

-bash-3.2# cat test.sh
#!/bin/bash
hello ()
{
i=1
until [ $i -gt 5 ]
do
echo $i
let i++
done
}
hello
-bash-3.2# sh test.sh
1
2
3
4
5

2、反回值

#!/bin/bash
hello ()
{
i=1
until [ $i -gt 5 ]
do
echo $i
let i++
done
}
hello
echo $?
-bash-3.2# sh test.sh
1
2
3
4
5
0

Copyright © Linux教程網 All Rights Reserved