Can a bash function be used in different scripts?

前端 未结 3 1547
孤独总比滥情好
孤独总比滥情好 2021-01-31 14:55

I\'ve got a function that I want to reference and use across different scripts. Is there any way to do this? I don\'t want to be re-writing the same function for different scrip

3条回答
  •  闹比i
    闹比i (楼主)
    2021-01-31 15:35

    Sure - in your script, where you want to use the function, you can write a command like

    source function.sh
    

    which is equivalent to including the contents of function.sh in the file at the point where the command is run. Note that function.sh needs to be in one of the directories in $PATH; if it's not, you need to specify an absolute path.

提交回复
热议问题