How to include file in a bash shell script

后端 未结 5 806
不知归路
不知归路 2021-01-29 23:53

Is there a way to include another shell script in a shell script to be able to access its functions?

Like how in PHP you can use the include directive with

5条回答
  •  清酒与你
    2021-01-30 00:29

    Syntax is source

    ex. source config.sh

    script - config.sh

    USERNAME="satish"
    EMAIL="satish@linuxconcept.com"
    

    calling script -

    #!/bin/bash
    source config.sh
    echo Welcome ${USERNAME}!
    echo Your email is ${EMAIL}.
    

    You can learn to include a bash script in another bash script here.

提交回复
热议问题