[root@a ~]#cat fun.txt #定義函數庫文件,方便在別的地方使用bash
addnum1() {函數
echo $[$1+$2]測試
}spa
addnum2(){ip
echo $[$1*$2]class
}test
deluser(){引用
userdel -r $user腳本
}di
[root@a ~]#pwd
/scripts/day2/
[root@a ~]#cat test.sh
#!/bin/bash
source /scripts/day2/fun.txt #腳本中引用函數文件
#source ./fun.txt #相對路徑方式
#. ./fun.txt #相對路徑方式,其中.至關於source
read -p "del user: " user
deluser #調用函數
addnum1 4 5 #調用函數
addnum2 24 3 #調用函數
[root@a ~]#sh test.sh #執行測試腳本
del user: abc
9
72
[root@a ~]#id abc #查看測試結果
id: abc: no such user