简体   繁体   English

如何在同一个shell中执行bash脚本

[英]How to execute bash script in same shell

I have a bash script which is calling three different commands and that execution must happen in one shell. 我有一个bash脚本,它调用三个不同的命令,并且执行必须在一个shell中执行。 I got it by adding && after each command like as follows- 我通过在每个命令之后添加&&得到它,如下所示 -

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脚本,它设置运行服务器的所有环境变量。

First, you will need to save save the command in a scriptfile, for example Myscript.sh . 首先,您需要将命令保存在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 . 代表当前的shell和第二个. for current directory. 对于当前目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM