shell 函数

函数定义

$ cat demo.sh 
#! /bin/bash

function fun() 
{
    echo "this is a function"
}

fun

$ ./demo.sh this is a function

 

函数调用

#! /bin/bash


function fun()
{
    local -n ref=$1    #引用,也可以写成 declare -n ref=$1,local 用于声明局部变量
    ref="this is other string"
}


aaa="this is a string"

echo $aaa

fun aaa

echo $aaa
$ ./demo.sh 
this is a string
this is other string  #对引用的操作相当于原始变量

 

 

函数参数、返回值

 

posted on 2019-06-16 21:02  rivsidn  阅读(106)  评论(0编辑  收藏  举报

导航