title: Bash - how can I check if I'm under Graphic Session?
body: <p>I want know how I can check in any Linux distro if I am inside an "Xorg / XFree86 / XSystem / Mir / Wayland" session.</p>
  
  <p>and if yes im under Xsession run commands
  and if not run commands in cli mode</p>
  
  <p>I tried the following:</p>
  
  <pre><code>xtty=`w -hs | awk '{print $2}' | sort -u | sed 's/^[tty \t]*//' | sed -n '$p'` &amp;&amp; echo "tty X(org/Free86/System) = $xtty"
  </code></pre>
  
  <p>But this just for knowing which tty I'm in.</p>
  
  <p>In some distros, the Graphics Modes are in tty1, tty5, tty6, or tty7.
  But, I want to know if I'm logged into that tty, and if I'm in a graphical session.</p>
  
  <p>Can someone please help me with this?</p>