I am trying to create a fun Terminal Screensaver which consists of the cmatrix package (one that turns terminal in one similar to the movie The Matrix) and xprintidle to determine idle time of the Terminal.

I took some help from this Thread answer at SuperUser and using a shell-script similar to it as follows:


set -x  # Used for debugging
IDLE_TIME=$((60*1000)) #a minute in milliseconds

# My screensaver function
    cmatrix -abs


while sleep $(((sleep_time+999)/1000)); do
    if [ $idle -ge $IDLE_TIME ]; then
        if ! $triggered; then
        sleep_time=$((IDLE_TIME -idle+100))

The script runs flawlessly when I run it in foreground using:


and I can see the matrix terminal triggered.

However If I run it in background with &; the function screen_saver() is triggered in the background and I cannot view it. The only possible way to see the matrix terminal is using fg which brings it foreground.


Is it possible to use the fg command in the function screen_saver() like:

     cmatrix -abs && fg

or similar option to bring it to the foreground within the shell-script?

I wish to add this script into my .bashrc so that it actually becomes a customizable feature. Is this possible?

  • 1
    Probably not, according to: unix.stackexchange.com/questions/224562/… – thrig Mar 29 '17 at 21:33
  • While you can't use fg the way you mean, this shouldn't prevent you from seeing the output of cmatrix. Can you reproduce the problem with a small script that doesn't use cmatrix? – Gilles Mar 29 '17 at 23:10

The fg, job commands are connected to interactive sessions only, and has no meaning in batch mode (scripts).

Technically, you could enable them by the -m flag, but it still would make little (if any) sense, as this only relates to interactive applications, where you can send jobs to back by ^Z, but since you don't have that interaction in a shell script, it makes it pointless.

The answer is in practice, No, you cant.


If you use tmux it has a option for "screensaver"

set -g lock-command "cmatrix -abs"
set -g lock-after-time 10 #inSeconds

Not exactly a answer to your question.

  • Will give this a try. Kudos for tmux – Shan-Desai Mar 30 '17 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.