简体   繁体   English

从shell脚本打开gnome-terminal并保持窗口打开

[英]Open gnome-terminal from shell script and hold window open

I'm trying to write a script that sets up my programming environment by taking as an argument the name of the project(directory) I want to open 我正在尝试编写一个脚本,通过将要打开的项目(目录)的名称作为参数来设置我的编程环境

so for example: ./my_script.sh sample_app 因此,例如: ./my_script.sh sample_app

And here is the script so far: 这是到目前为止的脚本:

#!/bin/bash

wmctrl -s 0
sublime &
sleep 2

wmctrl -s 1
google-chrome &
sleep 2

wmctrl -s 2
Dir="$echo /home/biTNumb/Projects/ruby/workspace/$1"
echo $Dir
gnome-terminal --window-with-profile=Guard -e ls &
#gnome-terminal -e cd /home/biTNumb/Projects/ruby/workspace/$1 && bundle exec guard &
#gnome-terminal -e cd /home/biTNumb/Projects/ruby/workspace/$1 && rails s &

The problem arises when the script executes: 执行脚本时会出现问题:

gnome-terminal --window-with-profile=Guard -e ls &

I get the message The child process exited normally with status 0. : 我收到消息The child process exited normally with status 0.

子进程正常退出,状态为0。

I can't use the terminal after (I can only close it) and the message hides some part of the output. 之后,我无法使用终端(我只能将其关闭),并且消息隐藏了输出的某些部分。 And yet, I have already created a profile and set the When command exits dropdown menu to 'Hold the terminal open' ... 但是,我已经创建了一个配置文件,并将“ 命令退出时”下拉菜单设置为“保持终端打开” ...

** I left the comments in the script so you can get the idea of what I'm trying to do ** 我在脚本中留下了注释,这样您就可以了解我要做什么

To execute multiple commands in the same gnome-terminal window, use semicolons ; 要在同一gnome-terminal窗口中执行多个命令,请使用分号; as separators like below: 如下面的分隔符:

gnome-terminal -- bash -c "command 1; command 2; ...; bash;"

The last command bash starts the command-line interpreter so that the terminal doesn't exit at the end (use $shell instead of bash for a more general solution). 最后一个命令bash启动命令行解释器,以使终端不会在最后退出(使用$shell而不是bash作为更通用的解决方案)。

This way you won't need to define a profile with the option Hold the terminal open when command exits and you won't get the message The child process exited with status 0 (which hide some parts of the output). 这样,您将不需要使用选项在命令退出时使终端保持打开状态”来定义配置文件,也不会收到消息The child process exited with status 0 (隐藏输出的某些部分)”的消息。

Here is what you might write (I use backslashes \\ to split lines): 这是您可能要写的内容(我使用反斜杠\\分割行):

gnome-terminal -- bash -c \
" ls ;\
cd /home/biTNumb/Projects/ruby/workspace/$1 && bundle exec guard ;\
cd /home/biTNumb/Projects/ruby/workspace/$1 && rails s;\
$bash;"    

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

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