We have here a read only Bash variable. I am not allowed to unset that variable.

$ echo $TMOUT

As a workaround I wrote those lines (that my session don't exit)


while (1) { print "\e[0n"; sleep 120; }

Is there an official package (rpm) that does similar (like above Perl code) in a CentOS7/RHEL7 repository? I don't like to open up a vim editor, I wish a command.

  • 4
    Usual solution to this is just run cat when stepping away from your session. And then ^C it on your return.
    – steve
    Aug 10 '15 at 14:36
  • I imposed a similar rule because I had people in my team that left terminals open for weeks in a row. Whilst I do agree 1800 is kinda of low, it must be there for some reason. People tend to notice deviations to the usual...yours sessions will stand out like a sore thumb. Jan 29 '16 at 9:04
  • when it's read-only, type: exec env TMOUT=0 bash
    – nightshift
    Aug 19 '18 at 3:39

Add this to the start of your .bash_profile ?

if [ ! -z "$TMOUT" ]; then
  env -i bash --init-file ~/.bash_profile

Beware the wrath of the sysadmins if you leave a gazillion old sessions running as a result of defeating their timeout rulings.

  • This is truly EVIL!
    – Ahi Tuna
    Dec 20 '19 at 15:47
  • 2
    The -i argument wipes out the environment. You can be more specific and only unset a single variable like so: env -u TMOUT bash --init-file ~/.bash_profile Mar 18 '20 at 9:59

You can issue perl commands from the command line...

perl -e '$|++; while (1) { print "\e[0n"; sleep 120; }'

or you could do the same in shell (a sh/bash example):

while sleep 120; do printf '\33[0n'; done

Or you could use watch:

watch -n 120 printf '\33[0n'

  • what is printf '\33[0n'? i know what the command line printf is. but what is being printed? Mar 13 '18 at 14:35
  • 1
    \33 is shorthand for the escape key <esc>[0n is not a known ANSI escape code, I imagine it was a typo and should of been <esc>[0m which resets the terminal colour for apps/terminals/tty's that support ANSI escape codes.
    – Drav Sloan
    Mar 14 '18 at 18:01

Here is the thing,
When the session variable is "Read Only" you have to replace the current shell process with the command by "exec"
So, the Answer to your question is:

$> exec env TMOUT=0 bash

But I recommend setting a higher timeout value

$> exec env TMOUT=3600 bash
  • If I add exec env TMOUT=0 bash to .bashrc, is it going to work in the same way?
    – notilas
    Nov 15 '20 at 5:41

Why aren't you switching to non-interactive session?

-bash: TMOUT: readonly variable
# unset TMOUT
-bash: unset: TMOUT: cannot unset: readonly variable
# su
# export TMOUT=10
# unset TMOUT

I my case, it is defined in /etc/profile.d/bash_autologout.sh:

readonly TMOUT
export TMOUT

To find it, I did:

sudo find /etc/ -name "*" | xargs sudo grep "TMOUT" 2>&1 | grep -v "filter..."

export TMOUT=0


You will have some activity and your session will stay and you could see how long it runs.

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.