How to print all environment variables in TCL? - environment-variables

In TCL, how can I print all environment variables using a single line command?

There is an array called env that stores all the environment variables. So you can simply do this:
puts [array get env]
or simply
parray env

Related

Setting a user space windows env var in Dockerfile

I have an environment variable defined in my windows settings as a user variable.
It is called GITLAB_AUTH_TOKEN.
In my Dockerfile I am trying to assign this variable to an environment variable called GAT like so:
ENV GAT=${GITLAB_AUTH_TOKEN}
This results in the GAT env var to be blank inside my container.
I have seen that it may be possible via docker-compose but that is not a solution for me, as my RUN command relies on this variable.

How can I use docker env files in shell scripts?

Docker env files look similar to shell scripts defining variables.
Unfortunately in env files, values cannot be quoted and so simply sourcing them only works if there are no "special" characters in the values.
VAR1=This_works
VAR2=This will not work
VAR3=This won't either
Is there any way you can use these files in a shell script?
My current approach is this:
eval $( perl -ne '
s/\x27/\x27\\\x27\x27/g;
s/^(\w+)=(.+)$/export $1=\x27$2\x27/ and print
' "path/to/env_file" )
So I'm searching for any quote in each line of the env file and replace it by '\''.
Then I'm modifying each line which starts with an identifier (\w+) followed by a = and any text (.+). So the VAR3 will become: export VAR3='This won'\''t either.
The modified line is then printed.
Everything which was printed is eval-ed and so the variables will be available in my shell's environment.
Are there other proposals how to achieve this?

Dockerfile single line `ENV` composing variables not working

I want to compose two environment variables: first define a "root" and in the same line use that to create a composed one. In example, filename and append extension.
Doing this container,
FROM centos:7
ENV ROOT_VAR=stringy ROOT_VAR_TGZ=${ROOT_VAR}.tar.gz
RUN echo ${ROOT_VAR} $ ${ROOT_VAR_TGZ}
The output for echo is
stringy $ .tar.gz
But when splitting each variable in an individual ENV command is composed correctly.
Is this the expected behaviour?
The behaviour is clearly explained in the docker reference document:
Environment variable substitution will use the same value for each variable throughout the entire instruction. In other words, in this example:
ENV abc=hello
ENV abc=bye def=$abc
ENV ghi=$abc
will result in def having a value of hello, not bye. However, ghi will have a value of bye because it is not part of the same instruction that set abc to bye.

Interpolate variables in environment variables definition with docker-compose.yml

How can I interpolate env vars when using docker-compose . if I have a following vars.env file :
VAR_1=value_1
VAR_2=value_1/value2
VAR_3=value_1/value3
I would like to interpolate using of VAR_1 like this
VAR_1=value_1
VAR_2=${VAR_1}/value2
VAR_3=${VAR_1}/value3
But it is not working. Any idea ?
This is not supported. You can however use an .env file to set the value of $VAR_1: https://docs.docker.com/compose/env-file/

Unable to Access ENV variable in rails

I am trying to use env variables in my rails app and set those variable values in ubuntu 14.04
I tried setting using export command
export mongodb_username="abc"
export mongodb_password="cde"
and also tried setting them in /etc/environment and in ~/.bashsrc
and printenv gives following results
>> printenv mongodb_username
=> abc
>> printenv mongodb_password
=> cde
BUT in RAILS APP or irb the output is following
>> ENV['mongodb_password']
=> nil
>> ENV['mongodb_username']
=> nil
I am missing something? Please help!!!
When setting an environment variable's value using export, that value is available only in the shell in which it was set, and its subshells. So you'll need to export those variables in every shell in which you need them.
However, you can automate this, of course.
If you have variables that you need frequently, one approach is to put their assignments in a shell script and then source the shell script in any shells you need them in (see http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x237.html for more on this).
If it's ok to have the variables be in effect in all your shells, then a simpler way is to export them from your startup script (probably ~/.bashrc).

Resources