Friday, 29 April 2022

TIL - read-only variables in Linux

 A co-worker was seeing an exception: -

 line 8: TMOUT: readonly variable

when trying to SCP a file from a remote Linux box.

I did some digging and found a RedHat article: -

Why does it prompt "bash: TMOUT: readonly variable" when sudo'ing or ssh'ing to the system? 

that said, in part: -

The TMOUT variable is usually defined read-only to avoid users from unsetting or modifying its value. Due to this it's not possible to set it twice.

I reproduced the problem on my Ubuntu 18.04 box: -

-bash: TMOUT: readonly variable

with a pair of scripts: -

The first script: -

cat /etc/profile.d/a.sh

readonly TMOUT=500; export TMOUT

sets TMOUT as readonly

The second script: -

cat /etc/profile.d/b.sh

TMOUT=600; export TMOUT

then tries to override it

which I validated: -

fgrep -R TMOUT /etc/profile.d/

/etc/profile.d/a.sh:readonly TMOUT=500; export TMOUT
/etc/profile.d/b.sh:TMOUT=600; export TMOUT

I left my colleague to dig into /etc etc. and see what was going on, but TIL about read-only variables 

3 comments:

PeptideCalculator said...
This comment has been removed by the author.
PeptideCalculator said...

Peptides: The Tiny Powerhouses Transforming Health, Fitness
Peptides Uses
Peptides Side effects
Peptides Benefits
But what exactly are peptides? Are they safe? And how do they actually help your body transform from the inside out?

manvendra said...

Finding the best old age home in India for your aging parents is one of the most important decisions you’ll ever make.
India top-10 luxury senior living facilities
old age home-in gurgaon
Best retirement homes Indiat
old-age homes in india
These communities offer 24/7 medical support, engaging recreational activities, nutritious meals designed for senior health, and most importantly—a vibrant social environment that combats loneliness.

Note to self - Firefox and local connections

 Whilst trying to hit my NAS from Firefox on my Mac, I kept seeing errors such as:- Unable to connect Firefox can’t establish a connection t...