码迷,mamicode.com
首页 > 系统相关 > 详细

shell 函数

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

标签:shell 函数

[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 函数

标签:shell 函数

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!