0

How do I read or access the TRAVERSE environment variable below?

nicholas@gondor:~$ 
nicholas@gondor:~$ printenv | grep PATH
WINDOWPATH=2
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
nicholas@gondor:~$ 
nicholas@gondor:~$ printenv | grep TRAVERSE
nicholas@gondor:~$ 
nicholas@gondor:~$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"

TRAVERSE="/home/nicholas/some_directory" nicholas@gondor:~$

I ran source ~/.bashrc without result. I expect that if I were to reboot the variable would be readable, but that seems extreme.

see also:

https://stackoverflow.com/q/39296472/4531180

  • Did you relogin after having added the TRAVERSE variable to /etc/environment? – Gunnar Hjalmarsson Jul 21 '21 at 10:53
  • no, I was trying to avoid that. I plan to muck around with some vars for a bit. that's the only way @GunnarHjalmarsson to reload or refresh the vars? – Nicholas Saunders Jul 21 '21 at 11:03
  • I'd say it's the "right" way. But you can simply do source /etc/environment which will update the current bash process with your latest changes. Well, new variables won't be exported to the environment that way, but only available as shell variables. – Gunnar Hjalmarsson Jul 21 '21 at 11:10
  • 1
    By definition, /etc/environment is read at login, by the login process, before shell or GUI is started, and only at that time. So relogin is a proper way to apply changes in this file. – raj Jul 21 '21 at 11:13
  • The full syntax of /etc/environment differs a lot from that of shell scripts, so while your particular file could be sourced, not all valid environment files can be. – muru Jul 21 '21 at 11:24
  • If you just want it for your current shell, why not just set and export the variable yourself? – muru Jul 21 '21 at 11:25
  • @muru: Possibly you mix it up with the ~/.pam_environment syntax. – Gunnar Hjalmarsson Jul 21 '21 at 13:52

1 Answers1

1

If you are using the bash shell

. /etc/environment

without the dot the variables defined in the script file are not passed to your current shell.

For Example:

$ cat b.sh
TRAVERSE="Another SomeThing"
$ echo $TRAVERSE

$ ./b.sh $ echo $TRAVERSE

$ . ./b.sh $ echo $TRAVERSE Another SomeThing $

SEWTGIYWTKHNTDS
  • 367
  • 1
  • 7