Hi, I am trying to write a simple bash script to join a screen session. If the session is not already running, it will start it and try to connect again.
The problem I encountered is related to the if statement; it should compare the output of the screen command with the error message, and if they are equal, start a session and attach. But it always goes to the else clause, printing out the error message that I checked: s
Both lines contain the same thing:
"There is no associated screen matching sctest."
but bash thinks they are different ...
Here's a bash script, what am I missing?
#!/bin/bash
screenOutput=$(screen -aA -x sctest);
failString="There is no screen to be attached matching sctest.";
if [ "$screenOutput" = "$failString" ]; then
echo "screen session not started. starting now...";
else
echo "$screenOutput";
fi
source
share