I currently have a case statement in bash that looks like so:
restart)
if kill -0 PID; then
while kill -0 PID; do
//exit script
done
screen -dmS screen1^M
screen -S screen1 -p 0 -X stuff '//code here'^M
else
//other stuff
fi
;;
When I use this script, the screen meant to be started as screen1 starts as screen1? instead. What is the cause of this, and how would I fix it?
You have extra carriage returns (those funny
^Ms) at the ends of some of your lines. Windows uses a carriage return followed by a linefeed (CRLF) as its line endings, but Linux uses just a plain linefeed, so any extraneous carriage returns are sometimes interpreted as regular characters, particularly in your case.To fix this, either delete the carriage returns from your script manually, or use a program such as
dos2unix(1)to convert the line endings (many other programs can also do this).