简体   繁体   English

使用bash脚本在同一终端上执行多个命令

[英]Execute multiple command onto same terminal using bash script

I am trying to run a bash script which contains few commands to execute. 我正在尝试运行一个bash脚本 ,其中包含一些要执行的命令。 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. 我已经写了一些命令来设置目录路径,并希望在那里建立一个文件夹。

Code : 代码:

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

Here, There are 2 problems : 在这里,有两个问题:

1) Two separate terminal are opened that I don't want. 1)打开了两个我不想要的终端。 I need only a single terimal where I will execute my commands. 我只需要一个整数即可执行命令。

2) sudo mkdir sphinxsearch folder is created at the default path from where I am executing my bash script. 2) sudo mkdir sphinxsearch文件夹是在我执行bash脚本的默认路径处创建的。 I need to create a folder inside /var/run/ 我需要在/ var / run /中创建一个文件夹

Each invocation of gnome-terminal will open a separate terminals. 每次对gnome-terminal调用都会打开一个单独的终端。

Try this: 尝试这个:

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

Here i am combining both options in a single invocation of gnome-terminal 在这里,我将两个选项组合在一个gnome-terminal调用中

sudo mkdir /var/run/sphinxsearch;

将在/var/run/创建文件夹

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

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