The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

If you can read me, I'm broken!

Views: 1,565     Votes:  3 
Tags: scripts   desktop-environments   virtual-console  
Link: 🔍 See Original Answer on Ask Ubuntu ⧉ 🔗

URL: https://askubuntu.com/q/1039023
Title: How to have script detect if terminal emulator is running in a desktop session or not?
ID: /2018/05/22/How-to-have-script-detect-if-terminal-emulator-is-running-in-a-desktop-session-or-not_
Created: May 22, 2018    Edited:  May 22, 2018
Upload: September 15, 2024    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


This is what I’ve been using:

# $TERM variable may be missing when called via desktop shortcut
CurrentTERM=$(env | grep TERM)
if [[ $CurrentTERM == "" ]] ; then
    notify-send --urgency=critical "$0 cannot be run from GUI without TERM environment variable."
    exit 1
fi

The reason for this code was this question: Desktop shortcut to Bash script crashes and burns

You can modify it to look like this:

# $TERM variable may be missing when called via desktop shortcut
CurrentTERM=$(env | grep TERM)
if [[ $CurrentTERM == "" ]] ; then
    nano ...
else
    gedit ...
fi
⇧ How do you manage journald log history on ubuntu core 16 how to do I force-yes on fsck  ⇩