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: 

    暂时还没找到错误在哪。

  • 相关阅读:
    JavaScript--Promise(1)
    JavaScript--创建对象
    JavaScript--JSON
    JavaScript--generator
    JavaScript--闭包(1)
    JavaScript--sort()
    JavaScript--filter()
    JavaScript--map()&reduce()
    JavaScript--map&set
    3.11
  • 原文地址:https://www.cnblogs.com/jacson/p/4800701.html
Copyright © 2011-2022 走看看