0

I want users to be able to set a variable they can use to define the level of verbosity when they run commands in the command line, when they initiate a new terminal session.

One way to set a variable is to include it in ~/.bashrc. In its simplest form, a command like echo export MYVAR=value >> ~/.bashrc already makes the variable available for future interactive shells.

Is this the best way to give additional control of commands to users? The problem is that I would like for users to change the value directly from the terminal rather than having to change the value by modifying their .bashrc.

Fatipati
  • 379

1 Answers1

1

Suggestion:

Include (in simplest form) a line having e.g.
source $HOME/.majvar.sh in .bashrc

... then manipulate the content of /home/$USER/.majvar.sh by any feasible means; e.g. create a python program of your own, if echo >.majvar.sh "export MYVAR=value" isn't "good enough".

clues:
https://www.google.com/search?channel=fs&client=ubuntu&q=python+name+of+logged+in+user
https://www.w3schools.com/python/ref_file_readline.asp
https://stackoverflow.com/questions/6159900/correct-way-to-write-line-to-file

Alternatively:
Make .majvar contain only the VALUE
and have .bashrc contain something similar to

if [ -r .majvar ] ;then
  set MYVAR="$( cat .majvar )"
  export MYVAR  # see man bash, search for 'export'
fi
Hannu
  • 5,374
  • 1
  • 23
  • 40