在 bash 中运行函数时找不到命令

在 bash 中运行函数时找不到命令

我正在尝试创建一个基本的 bash 脚本,该脚本关闭一个屏幕,然后启动一个新屏幕。

重新启动.sh

#!/bin/bash

set -o nounset
set -o errexit
trap 'echo "Aborting due to errexit on line $LINENO. Exit code: $?" >&2' ERR
set -o errtrace
set -o pipefail

SCR="bunny"
SCRIPT="/home/../run.sh" 

target_screen=$(find_screen $SCR)

main() {
    if find_screen $SCR >/dev/null; then
        close_screen
        start_script
    fi
}

function start_script {
    echo "Starting script with new screen"
    screen -d -m -t $SCR sh $SCRIPT
}

function close_screen {
    if find_screen $SCR >/dev/null; then
        echo "Found! Deleting $SCR"
        screen -S -X $target_screen quit
    fi
}

function find_screen {
    if screen -ls "$1" | grep -o "^\s*[0-9]*\.$1[ "$'\t'"](" --color=NEVER -m 1 | grep -oh "[0-9]*\.$1" --color=NEVER -m 1 -q >/dev/null; then
        screen -ls "$1" | grep -o "^\s*[0-9]*\.$1[ "$'\t'"](" --color=NEVER -m 1 | grep -oh "[0-9]*\.$1" --color=NEVER -m 1 2>/dev/null
        return 0
    else
        echo "$1"
        return 1
    fi
}

main "$@"

然而,当在 Ubuntu 16.04 上运行此脚本时,我得到以下信息:

    ./restart.sh: line 12: find_screen: command not found
Aborting due to errexit on line 12. Exit code: 127

我究竟做错了什么?

相关内容