如何在同一shell中执行bash脚本 [英] How to execute bash script in same shell

查看:44
本文介绍了如何在同一shell中执行bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个bash脚本,该脚本正在调用三个不同的命令,并且执行必须在一个shell中进行.我通过添加&&在每个命令之后,如下所示-

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-

CMD1 && CMD2 && CMD3

现在我需要的是-假设我在MAC机器上打开一个终端,所有命令都应该在开放外壳中运行,而不是在新的子外壳中运行.

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.

请注意,CMD1实际上是我的项目目录的源命令,它是一个bash脚本,用于设置运行服务器的所有环境变量.

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.

推荐答案

首先,您需要将命令保存在脚本文件中,例如 Myscript.sh .

First, you will need to save save the command in a scriptfile, for example Myscript.sh.

第二,您可以使用以下命令执行脚本文件以同时运行命令

Second, you can execute the script file to run your commands simultaneously using

. ./Myscript.sh

第一个.代表当前shell,第二个.代表当前目录.

The first . stands for current shell and the second . for current directory.

这篇关于如何在同一shell中执行bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆