2012-11-30 92 views
16

运行在新的终端shell脚本如何从像在Windows“开始test.bat的”,也应该在控制台模式下可正常工作的终端运行在Linux中一个新的终端shell脚本。从当前终端

+1

您需要支持哪些窗口环境? –

回答

18

这里有一个简单的例子,让你开始的命令替换LS:

写一个shell脚本,请在命令提示符处执行以下操作:

echo -e '#!/bin/sh\n echo "hello world"' > abc.sh 

写道:

#!/bin/sh 
echo "hello world" 

一个叫abc.sh

下一个文件,你要设置它通过为可执行文件:

./abc.sh 

和:

chmod +x abc.sh 

现在,你可以通过运行你应该看到:

hello world 

在你的终端。

要在新终端中运行它,你可以这样做:

gnome-terminal -x ./abc.sh 

,或者如果它是xterm

xterm -e ./abc.sh 

这里有一个list of different terminal emulators

或者,你只要运行它在当前的终端,而是一个后台它,而不是通过:

./abc.sh & 
+0

它的工作原理fineThank你这么多的帮助,和我有其他疑问将所有类型的支持Linux操作系统的gnome-terminal命令的? – mreaevnia

+0

@RaviKumar不,这并不普遍。它很大程度上取决于Linux发行版使用的桌面环境:http://en.wikipedia.org/wiki/List_of_terminal_emulators通常它是gnome-terminal或xterm –

+0

另外我需要在我使用linux机器时应该工作的命令远程登录会话。我希望这会有答案。 – mreaevnia

4

GNOME的尝试。

与您要运行

gnome-terminal -x sh -c "ls|less" 

我希望这是你想要的

2

我来这里是想弄清楚如何使一个脚本生成一个终端,并在其中运行的自我,所以对于那些想要这样做的人,我想出了这个解决方案:

if [ ! -t 0 ]; then # script is executed outside the terminal? 
    # execute the script inside a terminal window 
    x-terminal-emulator -e "$0" 
    # and abort running the rest of it 
    exit 0 
fi 
+0

请等待脚本上有参数调用吗?他们不会被授予新码头的脚本,对吗? – Kapichu