如何从Ubuntu的启动程序终端执行的脚本中正确启动脚本?

问题描述 投票:0回答:1

假设您的面板中有一个启动器,该启动器以终端模式启动名为foo.sh的脚本。

foo.sh然后在后台启动另一个称为bar.sh的脚本。

我遇到了问题:

首先:来自bar.sh的写入文件的名称不同。

第二和主要:bar.sh脚本不是独立的,并且在关闭终端时会死。

我在旧版16.04上进行了测试。机器。

foo.sh

#!/bin/bash

#read an user input
read -r -t 60 -p ":" foo
echo "$foo"

#call bar script
/home/$USER/bar.sh "10" "$foo" & disown

#show if bar.sh was started
echo $?

#sleep a short time to see the echo's
sleep 3

bar.sh

#!/bin/bash

#sleep some time
[[ -n "$1" ]] && sleep $1

#then write user input to file called output
echo "$2 - sleept $1 seconds" >> /home/$USER/output

如果在foo中睡眠的时间比在bar中睡眠的时间长输出文件被写入但称为输出? (以?结尾)。

但是如果bar中的时间较长,则foo完成并且关闭终端后,bar将被杀死。

任何想法如何正确设置bar.sh的后台实例?另一个开放的终端对我来说不是解决方案。THX!

bash ubuntu terminal panel execution
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.