![启动脚本来启动重复的子脚本吗?](https://linux22.com/image/1136526/%E5%90%AF%E5%8A%A8%E8%84%9A%E6%9C%AC%E6%9D%A5%E5%90%AF%E5%8A%A8%E9%87%8D%E5%A4%8D%E7%9A%84%E5%AD%90%E8%84%9A%E6%9C%AC%E5%90%97%EF%BC%9F.png)
我正在尝试让这个循环脚本在启动时运行。如果我添加“#! /bin/bash”,我可以从配置文件启动时自动启动它,但我无法让子窗口正常运行。- 我遗漏了什么?
num=0
while (($num <= 10)); do
gnome-terminal -x sh -c "obs --startstreaming; exec bash" &
timestamp=$( date)
echo "Started OBS in new terminal window at $timestamp"
sleep 4h
pkill -n obs
timestamp=$( date)
echo "Killed OBS @ $timestamp"
((num++))
#
done
谢谢!
答案1
下面应该可以做你想做的事:
#!/bin/bash
num=0
while ((num <= 10))
do
gnome-terminal -x sh -c "obs --startstreaming; exec bash" &
timestamp=$(date)
echo "Started OBS in new terminal window at $timestamp"
sleep 4h
pkill -n obs
timestamp=$(date)
echo "Killed OBS @ $timestamp"
((num++))
done
以下是输出shellcheck
对于您的脚本:
In test.sh line 1:
num=0
^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang.
In test.sh line 2:
while (($num <= 10)); do
^-- SC2004: $/${} is unnecessary on arithmetic variables.