使用.或者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

 

相关文章:

  • 2021-06-06
  • 2021-10-25
  • 2021-05-07
  • 2021-08-18
  • 2022-12-23
  • 2022-02-14
  • 2021-12-24
猜你喜欢
  • 2021-11-22
  • 2021-05-14
  • 2022-01-28
  • 2021-12-04
相关资源
相似解决方案