我已經做了足夠的搜索來發現這一點,但沒有運氣。我正在嘗試編寫一個Bash腳本,該腳本必須調用其他地方定義的函數。在Bash腳本中調用一個函數
例如,我有一個殼test.sh
#!/bin/bash
# Shell - test.sh
function1() {
echo "Inside function 1"
}
function1
function2
exit 0
我有具有函數2不同的文件,
$ cat function2
function2() {
echo "Inside function 2"
}
現在,當我運行test.sh, (Q1)它如何知道在哪裏可以找到function2? (Q2)沒有顯示功能2的回波輸出
任何輸入都很棒。
嗨,感謝您的回答。但是,令我驚訝的是,當我使用「$。/ test.sh」執行shell時,我得到「Inside function 1」的輸出。如果shell沒有找到「function2」,它應該拋出一個錯誤,「找不到函數或者其他東西」。我覺得不知何故該函數被調用,但消息沒有顯示。
感謝, 拉維
你'source'第一(你可以用'.'作爲'source'快捷方式) –
第二個文件@ DavidC.Rankin它周圍的其他方式,'source'命令是長'''命令的版本,但'.'首先出現。 – hek2mgl
我總是把它倒退,謝謝。我得到的雞或雞蛋也錯'')' –