How to include file in a bash shell script

后端 未结 5 850
不知归路
不知归路 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:27

    Simply put inside your script :

    source FILE
    

    Or

    . FILE # POSIX compliant
    

    $ LANG=C help source
    source: source filename [arguments]
    Execute commands from a file in the current shell.
    
    Read and execute commands from FILENAME in the current shell.  The
    entries in $PATH are used to find the directory containing FILENAME.
    If any ARGUMENTS are supplied, they become the positional parameters
    when FILENAME is executed.
    
    Exit Status:
    Returns the status of the last command executed in FILENAME; fails if
    FILENAME cannot be read.
    

提交回复
热议问题