An issue only happening by using the debug mode.
Because function return text and that text is used for the code for next step,
debug mode break it and add the debug content to the return of the function.
I'm suggestion debug to use error output rather than normal output (normal is catched by your code).
Here is the change:
diff --git a/factorio b/factorio
index 3fb7ad3..b9389d1 100755
--- a/factorio
+++ b/factorio
@@ -12,7 +12,7 @@
function debug() {
if [ "${DEBUG-0}" -gt 0 ]; then
- echo "DEBUG: $*"
+ echo "DEBUG: $*" 1>&2
fi
}
Original one

Patched one

An issue only happening by using the debug mode.
Because function return text and that text is used for the code for next step,
debug mode break it and add the debug content to the return of the function.
I'm suggestion debug to use error output rather than normal output (normal is catched by your code).
Here is the change:
Original one

Patched one
