Expect use environment variable if defined

Here is how to use a variable

set a FOOBAR
puts "the contents of a is $a"

Here is how to use an environment variable in expect/tcl.

puts "env var MYVAR is $env(MYVAR)"

Here is what happens when you try to use an environment variable if it is undefined.

$ ./mine.exp
no such variable
    (read trace on "env(MYVAR)")
    invoked from within
"puts "$env(MYVAR)""
    (file "./mine.sh" line 2)

Here is how to use a fallback value if the environment variable fails.

set MYVAR defaultvalue
catch {set MYVAR $env(PREFERRED_VALUE)}
puts "$MYVAR"



  1. How to access environment variables in an Expect script? – Stack Overflow



Restart cinnamon from command line

When cinnamon freezes up and needs to be restarted, you can restart it from Cinnamon itself or from a different terminal.

In Cinnamon

Press ALT+F2. Type in the letter r and press enter.

On the command line

To switch to another console terminal, press CTRL+ALT+F2.
On this terminal, type this command.

pkill -HUP -f "cinnamon --replace"



  1. User sim at askubuntu.com https://askubuntu.com/questions/143838/how-do-i-restart-cinnamon-from-the-tty/523436#523436

Logout from Different Desktop Environments from Command Line


Some people spend all day in terminals, even though there’s a desktop environment running. I normally have four different terminals open on my main screen, in a normal quadrant pattern. I arrange them on the taskbar so they are clockwise, starting in the upper left quadrant.


Suppose you want to close your session, without having to use the mouse or pressing the Super key or anything like that.

You want to enter a command from your terminal that will close your session. Here is a list of how to do that, for each different desktop environment (DE) I’ve collected so far.

Logout from desktop environments

Logout from cinnamon from command line

cinnamon-session-quit --logout --force

Logout from xfce from command line

xfce-session-quit -l

Logout from GNOME Shell from command line


Logout from KDE4 from command line

qdbus org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout -1 -1 -1

Logout from KDE5 from command line

With confirmation

qdbus org.kde.ksmserver /KSMServer logout 1 3 3

Without confirmation

qdbus org.kde.ksmserver /KSMServer logout 0 3 3

Logout from desktop environment from command line

loginctl terminate-user username



  1. Cinnamon https://forums.linuxmint.com/viewtopic.php?t=177547
  2. Gnome https://askubuntu.com/questions/15795/how-can-you-log-out-via-the-terminal#15796
  3. KDE4 http://www.techlw.com/2012/07/log-out-in-ubuntu-from-command-line.html
  4. KDE5 Plasma https://forum.kde.org/viewtopic.php?f=289&t=135065
  5. Extra reading for KDE https://majewsky.wordpress.com/2009/07/11/shutdown-your-machine-automatically-or-from-remote/