screen/byobu presence inferred by an environment variable

Bug #1179304 reported by Jan Dahl
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu Server Guide

Bug Description

Hey there,

I've recently discovered that $STY is set when running a terminal in byobu (or screen). I think i would be suitable to add to the documentation (

Proposed addition:

You can check for the presence of byobu in your scripts by checking for the $STY environment variable, e.g.

<pre>if [ -n $STY ]; then...</pre>

Tags: byobu screen
affects: ubuntu-docs (Ubuntu) → serverguide
Revision history for this message
Jan Dahl (ubuntu-com-ninja) wrote :

Here's an example script that I use (from my own repo:

#!/usr/bin/env bash

# If running in screen, set trap to fall back to current hostname
# If you want it to blank, replace ${HOSTNAME} with a space :-)
if [ -n $STY ] ; then
  trap 'echo -n -e "\033k${HOSTNAME}\033\\"' 0 1 2 15
  echo -n -e "\033k$1\033\\"
/usr/bin/env ssh $*

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers