从当前终端在新终端中运行 shell 脚本 [英] Run a shell script in new terminal from current terminal

查看:50
本文介绍了从当前终端在新终端中运行 shell 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你如何在 Linux 的新终端中从 Windows 中的start test.bat"这样的终端运行 shell 脚本,它也应该在控制台模式下工作.

How do you run a shell script in a new terminal in Linux from a terminal like "start test.bat" in Windows, also it should be working in the console mode.

推荐答案

这是一个让您入门的简单示例:

Here's a simple example to get you started:

要编写 shell 脚本,请在命令提示符下执行此操作:

To write a shell script, do this on your command prompt:

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

这样写道:

#!/bin/sh
echo "hello world"

到一个名为 abc.sh

接下来,您希望通过以下方式将其设置为可执行:

Next, you want to set it to executable by:

chmod +x abc.sh

现在,您可以通过以下方式运行它:

Now, you can run it by:

./abc.sh

你应该看到:

hello world

在您的终端上.

要在新终端中运行它,您可以:

To run it in a new terminal, you can do:

gnome-terminal -x ./abc.sh

或者,如果是 xterm:

xterm -e ./abc.sh

这是一个不同终端模拟器的列表.

或者,您只需在当前终端中运行它,而是通过以下方式将其作为后台运行:

Alternatively, you just run it in your current terminal, but background it instead by:

./abc.sh &

这篇关于从当前终端在新终端中运行 shell 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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