I am trying to create a basic bash script that closes a screen and then starts a new one.



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


target_screen=$(find_screen $SCR)

main() {
    if find_screen $SCR >/dev/null; then

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

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
        echo "$1"
        return 1

main "$@"

However when running this script on Ubuntu 16.04, I get the following:

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

What am I doing wrong?

closed as off-topic by Kusalananda, Jeff Schaller, user34720, Satō Katsura, phk May 25 '17 at 21:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Kusalananda, Jeff Schaller, Community, Satō Katsura, phk
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 7
    You're calling target_screen=$(find_screen $SCR) before the find_screen command has been defined. – Stéphane Chazelas Feb 24 '17 at 22:38
  • Thanks. There are a few more problems now. When starting the screen, I get the black screen i.imgur.com/RCojPmK.png and for some reason, it not only restarts the bunny screen but also appends another screen with a weird name with two dots. Any ideas? – kinx Feb 25 '17 at 0:12
  • @kinx That's a new question. Consequently, you should post a new question! – leekaiinthesky Feb 27 '17 at 0:48