How to use a function defined in a bash profile in a bash script?

[亡魂溺海] 提交于 2019-12-01 05:01:41

问题


I have a Projection function in my bash_profile. Now I am trying to call this function from a bash script however I get a not found error. How do I make the projection function visible to the bash script?


回答1:


You must export the function

export -f foo

ref




回答2:


The sane but not necessarily elegant approach is to put the function in a separate file, and source it from your profile and from your script.

You need to export the function if you want to make it available to all your scripts, but -- as with global variables -- this is not very maintainable in the long run.



来源:https://stackoverflow.com/questions/15941267/how-to-use-a-function-defined-in-a-bash-profile-in-a-bash-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!