Can a bash function be used in different scripts?

前端 未结 3 1550
孤独总比滥情好
孤独总比滥情好 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条回答
  •  死守一世寂寞
    2021-01-31 15:38

    Yes..you can! Add source function_name in your script. I prefer to create variable eg.VAR=$(funtion_name),if you add the source function_name after #!/bin/bash then your script first execute imported function task and then your current script task so its better to create variable and used anywhere in script. thank you..Hope its work for you:)

提交回复
热议问题