Execute multiple command onto same terminal using bash script

大城市里の小女人 提交于 2019-12-25 06:59:24

问题


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.

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. 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. I need to create a folder inside /var/run/


回答1:


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

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




回答2:


sudo mkdir /var/run/sphinxsearch;

will create the folder in /var/run/



来源:https://stackoverflow.com/questions/26375579/execute-multiple-command-onto-same-terminal-using-bash-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!