How to run a shell script on a Unix console or Mac terminal?

前端 未结 7 1075
执念已碎
执念已碎 2020-11-28 16:54

I know it, forget it and relearn it again. Time to write it down.

7条回答
  •  南方客
    南方客 (楼主)
    2020-11-28 17:34

    If you want the script to run in the current shell (e.g. you want it to be able to affect your directory or environment) you should say:

    . /path/to/script.sh
    

    or

    source /path/to/script.sh
    

    Note that /path/to/script.sh can be relative, for instance . bin/script.sh runs the script.sh in the bin directory under the current directory.

提交回复
热议问题