文章出處

先創建名稱為 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: 

暫時還沒找到錯誤在哪。


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()