首页 > 系统服务 > 详细

shell 函数

时间:2017-01-10 18:19:18      阅读:229      评论:0      收藏:0      [点我收藏+]

[root@OBird shell]# vim fun.sh

#!/bin/bash

function mysum()    {

       sum=$[$1+$2]

       echo $sum

}

a=1

b=2

mysum $a $b


[root@OBird shell]# sh fun.sh 

3


[root@OBird shell]# sh -x fun.sh 

+ a=1

+ b=2

+ mysum 1 2

+ sum=3

+ echo 3

3



[root@OBird shell]# a=(1 2 3 4 5)

[root@OBird shell]# echo $a

1


[root@OBird shell]# echo ${a[@]}

1 2 3 4 5


[root@OBird shell]# echo ${a[4]}  #输出其中一个元素

5


[root@OBird shell]# a[6]=8  #定义元素


[root@OBird shell]# a[2]=9  #更改元素

[root@OBird shell]# echo ${a[@]} #再次输出

1 2 9 4 5 8

[root@OBird shell]# echo ${#a[@]}  #打印数组数量

6




本文出自 “CBO#Boy_Linux之路” 博客,请务必保留此出处http://20151213start.blog.51cto.com/9472657/1890756

shell 函数

原文:http://20151213start.blog.51cto.com/9472657/1890756

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!