Search code examples
linuxaliasgnu-screen

Using bash with screen in an alias


I have a screen session that is always running in a separate user (for a minecraft server). Each time I want to attach to this screen, I use su -c 'screen -r mc-1.18.2' minecraft to attach back to this screen.

I wanted to make an alias for this command just so I didn't have to type it out or go up in the command history each time. I added alias mcconsole="su -c 'screen -r mc-1.18.2' minecraft" to my ~/.bash_aliases folder. My other aliases work just fine but when I run mcconsole I am left with a brand new screen session. I am not sure where the hiccup is when attaching to the screen session (which is running as I can attach to it normally).


Solution

  • maybe try to invert simple and double quotes, something like:

    alias mcconsole='su -c "screen -r mc-1.18.2" minecraft'

    or escape double quotes inside:

    alias mcconsole="su -c \"screen -r mc-1.18.2\" minecraft"