Bash,调用源自脚本的函数? [英] Bash, call a function sourced from a script?
本文介绍了Bash,调用源自脚本的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有2个脚本
test1.sh
#!/bin/sh
. ./test2.sh
foo
test2.sh
#!/bin/sh
foo(){
echo "bar"
}
如果我叫第一个脚本就可以了
If I call first script it is ok
$ ./test1.sh
bar
但是如果之后我尝试调用 foo
,它将无法正常工作.
But if I try to call foo
after that it will not work.
$ foo
bash: foo: command not found
推荐答案
如果我输入test1.sh,它将给出期望的结果.
If I source test1.sh it gives the desired result.
$ . test1.sh
bar
$ foo
bar
这篇关于Bash,调用源自脚本的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文