四種方式: shell
. script # using the . (dot) source script # using the `source` command sh /path/to/script # using the `sh` command /path/to/script # using the path (absolute or relative)
說明:bash
. (點)和 source不徹底等價。.(點)僅在bash類shell能正常工做,source在bash類和csh類shell都能正常工做。它們共同點是都會就地執行腳本,換句話說,該腳本的全部函數和非本地變量都會保留。舉個例子,若是被執行的腳本經過cd命令進入了一個目錄,腳本執行完畢後,你仍然處於這個目錄。函數
另外兩種方法使用了指定的解析命令。如無明示,將會使用腳本首行指定的默認解析命令。它們的共同點是不保留腳本內的變量。亦即不影響調用時的環境。code