启动脚本来启动重复的子脚本吗?

启动脚本来启动重复的子脚本吗?

我正在尝试让这个循环脚本在启动时运行。如果我添加“#! /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.

相关内容