文章出處
文章列表
先創建名稱為 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:
暫時還沒找到錯誤在哪。
文章列表
全站熱搜