【发布时间】:2020-04-04 11:39:18
【问题描述】:
假设您的面板中有一个启动器,它在终端模式下启动一个名为 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!
【问题讨论】:
-
我投票结束这个问题,因为你的问题更适合问 Ubuntu
标签: bash ubuntu terminal panel execution