#文件.bashrc
#添加语句
. /home/user/func.lib
-----------------------------------
#文件func.lib
addem () {
echo $[$1+$2]
}
multem () {
echo $[$1 * $2]
}
divem () {
if [ $2 -ne 0 ]
then
echo $[$1/$2]
else
echo -1
fi
}
------------------------------
#命令行执行没问题
$ addem 10 5;multem 10 5;divem 10 5
15
50
2
------------------------------
#放脚本不行
#! /bin/bash
# 测试脚本
#脚本文件名 test.sh
value1=10
value2=5
result1=$(addem $value1 $value2)
result2=$(multem $value1 $value2)
result3=$(divem $value1 $value2)
echo "the result of adding them is : $result1"
echo "the result of multplying them is : $result2"
echo "the result of dividing them is : $result3"
#执行
$ ./test.sh
./new.sh:行4: addem: 未找到命令
./new.sh:行5: multem: 未找到命令
./new.sh:行6: divem: 未找到命令
the result of adding them is :
the result of multplying them is :
the result of dividing them is :
-------------------------------------------
不是说新shell创建都要扫描.bashrc的么,这个新脚本执行的时候难道没有扫描这个文件么?求解答~