oh~Buffalo 2021-04-26 10:53 采纳率: 0%
浏览 130

Centos7下在用户.bashrc下定义的函数,在新脚本中还是显示无法找到,有大佬解释一下么?

#文件.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的么,这个新脚本执行的时候难道没有扫描这个文件么?求解答~

  • 写回答

3条回答 默认 最新

  • CSDN专家-杨俊 2021-04-26 11:01
    关注

    应该是脚本函数没有生效,可以实现命令:source ~/.bashrc使得配置文件生效

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?