shell 文件的包含

使用.或者source

api.sh

function intadd()
{
    let data=$1+$2
    echo $data
}

test.sh

#!/bin/bash
. api.sh
read d1 d2
ret=$(intadd $d1 $d2)
echo $ret
 
source api.sh
read d1 d2
res=$(intadd $d1 $d2)
echo $res

输出

bogon:Desktop macname$ ./test.sh 
6 2
8
6 2
8
原文地址:https://www.cnblogs.com/sea-stream/p/11397662.html