使用bash脚本在同一终端上执行多个命令 [英] Execute multiple command onto same terminal using bash script

查看:405
本文介绍了使用bash脚本在同一终端上执行多个命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行一个 bash脚本,其中包含一些要执行的命令。我想打开一个终端,并执行多个命令。我已经写了一些命令来设置目录路径,并想在其中建立一个文件夹。

I am trying to run a bash script which contains few commands to execute. I want to open a terminal and execute multiple commands into it. I have written commands to set the directory path and want to make a folder there.

代码:

gnome-terminal --working-directory=/var/run/ 
gnome-terminal -e "bash -c \"sudo mkdir sphinxsearch; exec bash\""

这里,有2个问题:

1)打开了两个我不想要的终端。我只需要一个单个十进制即可执行命令。

1) Two separate terminal are opened that I don't want. I need only a single terimal where I will execute my commands.

2) sudo mkdir sphinxsearch 文件夹已创建在执行我的bash脚本的默认路径中。我需要在 / var / run /

2) sudo mkdir sphinxsearch folder is created at the default path from where I am executing my bash script. I need to create a folder inside /var/run/

推荐答案

每次调用 gnome-terminal 将打开一个单独的终端。

Each invocation of gnome-terminal will open a separate terminals.

尝试以下操作:

gnome-terminal --working-directory=/var/run/ -e "bash -c \"sudo mkdir sphinxsearch; exec bash\""

在这里,我将两个选项合并为一个 gnome-terminal

Here i am combining both options in a single invocation of gnome-terminal

这篇关于使用bash脚本在同一终端上执行多个命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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