Reputation: 3
So I'm trying to preserve the \n so it prints it instead of bash interpreting it as a newline. I'm writing to a screen that runs a server that needs to use the \n to start a newline in that server. Calling LOGINMESSAGE like this
LOGINMESSAGE="Welcome to the server $INITPLAYER! \n Type !HELP for chat commands"
as_user "screen -p 0 -S $SCREENID -X stuff $'/server_message_to info \"$INITPLAYER\" \"$LOGINMESSAGE\"\n'"
In the screen I need it to say this /server_message_to info info $INITPLAYER! "Welcome to the server $INITPLAYER! \n Type !HELP for chat commands". So in the screen in needs to keep the \n. Currently it removes it or breaks the command to the game. So basicly what I'm trying to do is have it type to the screen exactly like that keeping the \n in tact.
EDIT: Fixed thanks to chepner
Upvotes: 0
Views: 74
Reputation: 531490
The problem is that the value of LOGINMESSAGE
ends up being evaluated inside a $'...'
-quoted string, where the \n
pair is converted to a newline. To prevent that, simply move all but the final \n
outside the $'...'
. The shell automatically concatenates strings that are not separated by whitespace.
as_user "screen ... '/server_message_to info \"$INITPLAYER\" \"$LOGINMESSAGE\"'$'\n'"
Upvotes: 1