【发布时间】:2019-03-28 13:00:34
【问题描述】:
“Debian 9 64x - LXDE”
我尝试在 bash 中创建安装脚本。假设我想安装 samba。我从主脚本调用 samba \folder\samba.sh 的安装脚本。脚本 samba.sh 应该在新的终端窗口中执行,所以我可以观察安装错误。
脚本应该像下面描述的那样工作:
- 脚本
/mainscript.sh仅提供用户信息、交互,并执行多个下标(/folder/subscripts.sh)。 - 脚本
/mainscript.sh需要创建一个新的终端窗口,传递subscript.sh的路径和名称,并在新的终端窗口中执行。 - 脚本
/mainscript.sh当时只能执行一个下标(/folder/subscript.sh)!如果subscript.sh正在运行,则主脚本必须等到新的终端窗口关闭。 -
subscript.sh以 root 权限执行一些代码。
问题:
如何新建一个终端窗口,传递下标,在新的终端窗口中执行?
如何确保脚本 (
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
【问题讨论】:
标签: bash terminal debian subscript