Mainscript 在新终端中执行 subscripts window

Mainscript executes subscripts in a new terminal window

"Debian 9 64x - LXDE"

我尝试在 bash 中创建安装脚本。假设我想安装 samba。我从主脚本调用 samba \folder\samba.sh 的安装脚本。脚本 samba.sh 应该在新终端 window 中执行,所以我可以观察安装错误。

脚本应该像下面描述的那样工作:

问题:

  1. 如何新建终端window,传入下标,在新终端执行window?

  2. 如何确保脚本(mainscript.sh)一次只运行一个下标(subscript.sh)?

示例:

mainscript.sh

    #!/bin/sh
    # This is the content of the mainscript.sh
    # subscript1 and subscript2 must not be executed at the same time!
    # the mainscript needs to wait when a subscript gets executed!

    echo "hello, this script runs in terminal window (((A)))"
    xterm /opt/subscript1.sh
    echo "samba - Installed"
    xterm /opt/subscript2.sh
    echo "samba - removed"

subscript1.sh

    #!bin/sh
    # This is the content of the subscript1

    echo "This script runs in a new terminal window (((B)))"
    apt-get install samba
    # instructions done .... close the terminal window (((B))) now

subscript2.sh

    #!bin/sh
    # This is the content of the subscript2

    echo "This script runs in a new terminal window (((C)))"
    apt-get remove samba
    # instructions done .... close the terminal window (((C))) now

在澄清您实际上想要一个新终端 window 出现在 LXDE 之后,这是一个可能的解决方案。

Debian LXDE 可能安装了 xterm 或 lxterminal。下面的示例使用 lxterminal。对于 xterm 使用 "xterm -e command"

首先在自己的 window 中执行 manscript.sh:

$ lxterminal --command=/mainscript.sh
#!/usr/bin/sh

<section that provides user information>

# Call subscripts that will run in sequence
lxterminal --command=/folder/subscripts.sh

当 subscripts.sh 完成后,新终端 window 将关闭并且 return 控制权交给 mainscript.sh 通过依次调用它们,您一次只能获得 运行 的一个下标。