#文件.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的么,这个新脚本执行的时候难道没有扫描这个文件么?求解答~
应该是脚本函数没有生效,可以实现命令:source ~/.bashrc使得配置文件生效
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
非常感谢您使用有问必答服务,为了后续更快速的帮您解决问题,现诚邀您参与有问必答体验反馈。您的建议将会运用到我们的产品优化中,希望能得到您的支持与协助!
速戳参与调研>>>https://t.csdnimg.cn/Kf0y