zoukankan      html  css  js  c++  java
  • shell script创建库

    先创建名称为 myfuns 

    # my script functions
    
    function addem {
      echo $[ $1 + $2 ]
    }
    
    function multem {
      echo $[ $1 * $3 ]
    }
    
    function divem {
      if [ $2 -ne 0 ]
      then
        echo $[ $1 / $2 ]
      else
        echo -1
      fi
    }

    然后创建脚本,名称为: test14.sh 

    #!/bin/bash
    # using functions defined in a library file
    ./myfuns
    
    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 multiplying th is: $result2"
    echo "The result of dividing them is: $result3"

    其中 ./myfuns 是调用该文件,具体使用时可能因路径不同而使用不同的路径,本文中两个文件放在同一目录下

    运行  sh test14.sh 

    输出:

    test14.sh: line 7: addem: command not found
    test14.sh: line 8: multem: command not found
    test14.sh: line 9: divem: command not found
    The result of adding them is: 
    The result of multiplying th is: 
    The result of dividing them is: 

    暂时还没找到错误在哪。

  • 相关阅读:
    字串变换
    单词接龙
    二叉搜索树
    搜索专题(未完)
    单调栈
    单调队列练习(切蛋糕&好消息,坏消息)
    队列专题
    滑动窗口/【模板】单调队列
    Linux下如何查看硬件信息?
    Git 居然可以用来跟女神聊天?
  • 原文地址:https://www.cnblogs.com/jacson/p/4800701.html
Copyright © 2011-2022 走看看