bash 如何在同一个shell中执行bash脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44122714/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to execute bash script in same shell
提问by Sam
I have a bash script which is calling three different commands and that execution must happen in one shell. I got it by adding && after each command like as follows-
我有一个 bash 脚本,它调用三个不同的命令,并且该执行必须在一个 shell 中进行。我通过在每个命令后添加 && 来得到它,如下所示 -
CMD1 && CMD2 && CMD3
Now what i need is- lets say i open a terminal on my MAC machine, all commands should run in open shell not in new sub-shell.
现在我需要的是 - 假设我在我的 MAC 机器上打开一个终端,所有命令都应该在打开的 shell 中运行,而不是在新的子 shell 中。
As a side note- CMD1 is actually a source command to my project directory which is a bash script which sets all the environment variable for running server.
附带说明 - CMD1 实际上是我项目目录的源命令,它是一个 bash 脚本,它设置运行服务器的所有环境变量。
回答by Nikhil Fadnis
First, you will need to save save the command in a scriptfile, for example Myscript.sh
.
首先,您需要将命令保存在脚本文件中,例如Myscript.sh
.
Second, you can execute the script file to run your commands simultaneously using
其次,您可以使用脚本文件同时运行您的命令
. ./Myscript.sh
The first .
stands for current shell and the second .
for current directory.
第一个.
代表当前shell,第二个.
代表当前目录。