簡體   English   中英

從shell腳本中的另一個文件中讀取命令?

[英]Reading commands from another file in a shell script?

看到我想在我的shell腳本中使用source命令。 現在,當我在終端上鍵入source時,它顯示為

-bash: source: filename argument required
source: usage: source filename [arguments]

現在當我像這樣在我的shell腳本中使用它時

#!/bin/sh
source

並另存為test.sh

然后像這樣跑

./test.sh: 2: source: not found

如何解決這個問題呢?

您使用sh而不是bash運行腳本。 source不在純sh存在,但是您可以使用. 相反,它意味着同一件事。

#!/bin/sh
. /path/to/other/script
function_defined_in_other_script

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM