I want to propagate an env variable into an xterm from tcl command.
I used the followings from the xterm:
tclsh> set ::env(MYVAR) XXXX
tclsh> parray env
tclsh> MYVAR= XXXX
But after quiting the tclsh session the MYVAR is not setted in the xterm:
xterm> env | grep MYVAR
xterm>
How to make it ?
As Donal says, environment variables only propagate from a process to its child processes, not back to its parent. So the simplest approach would be to start a new xterm as a child of tclsh. Your Tcl code would do:
set ::env(MYVAR) XXXX
exec xterm &
This will open a new xterm which will have MYVAR set. Of course I have no idea whether this fits with other requirements you may have.
Related
Can I do character substitution to set one ENV value based on another one?
My scenario...
ENV tableauVersion 2019-4-0
ENV tableauVersionDots 2019.4.0
ENV tabcmdURL https://downloads.tableau.com/esdalt/${tableauVersionDots}/tableau-tabcmd-${tableauVersion}_all.deb
Obviously, i'd like to be able to define tableauVersionDots based on the tableauVersion ENV variable (i.e. replace - with .)
No. The only substitutions it's possible to do in Dockerfile ENV statements are the ones shown in the Dockerfile documentation: $variable, ${variable}, ${variable:-default}, or ${variable:+yes it is set}.
For URLs like that you don't really need them in an environment variable. If you do need to compute it and then fetch it you could do it within a single RUN statement
RUN tableauVersionDots=$(echo "$tableauVersion" | sed 's/-/./g') \
&& curl -LO https://downloads.tableau.com/esdalt/${tableauVersionDots}/tableau-tabcmd-${tableauVersion}_all.deb
The variable setting won't survive beyond this RUN statement (and in shell space I haven't even bothered to export it) but that's probably okay just for fetching a URL.
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.
I am trying to do "unset" of an env variable from my rpm.spec file. which is not happening
Note that i am not exporting that env inside my rpm.spec.(i will do an export my self in cmd line)
$export user=akshatha
$export group=akshatha1
rpm.spec:
%postun
unset user
unset group
uninstalling the package:
$rpm -e (rpm_package)
check whether the value is unset or not(which is not unset):
$ echo $user
akshatha
$echo $group
akshatha1
You are mixing up what an rpm package is and what it can do.
Environment variables are set within a (bash, shell,...) Session. When you set variables and you start a new session, these variables are gone.
Rpm packages are supposed to install files at certain locations, to make permanent, system wide changes (like installing software). An rpm package, nor the installation of an rpm package is linked to your bash session (the installation will run in a separate session by the way).
You should not try to influence your environment variables with your rpm.
In the very unlikely case that you do need to export some kind of environment variable, then you should try to make it system wide available, for example declaring it in /etc/bashrc or something similar.
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).
I am not able to set env variables through an executable csh/tcsh script
An env variable set inside a csh/tcsh executable script "myscript"
contents of the script ...
setenv MYVAR /abc/xyz
which is not able to set on the shell and reports "Undefined variable"
I have made the csh/tcsh script as executable by the following shell command
chmod +x /home/xx/bin/myscript
also the path is updated to
set path = (/home/xx/bin $path)
which myscript
/home/xx/bin/myscript
When I run the script on command line and echo the env variable ..
myscript
echo $MYVAR
MYVAR "Undefined variable"
but if i source on command line
source /home/xx/bin/myscript
echo $MYVAR
/abc/xyz
you need to source your code rather than execute it so that it is evaluated by the current shell where you want to modify the environment.
You can of course embed
source /home/xx/bin/myscript
within your .cshrc
the script does not need to be executable or have any #! shebang (though they don't hurt)
This is not how environment variables work.
An environment variable is set for a process (in this case, tcsh) which is passed on to all child processes. So when you do:
$ setenv LS_COLORS=foo
$ ls
You first set LS_COLORS for the tcsh process, tcsh then starts the child process ls which inheres tcsh's environment (including LS_COLORS), which it can then use.
However, what you're doing is setting the environment is a child process, and then want to propagate this back to the parent process (somehow). This is not possible. This has nothing to do with tcsh, it works like this for any process on the system.
It works with source because source reads a file, and executes it line-by-line in the current process. So it doesn't start a new tcsh process.
I will leave it as an exercise to you what the implications would mean if it would be possible :-) Do you really want to deal with unwise shell scripts that set some random environment variables? And what about environment variables set by a php process, do we want those to go back in the parent httpd process? :-)
You didn't really describe what goal you're trying to achieve, but in general, you want to do something like:
#!/bin/csh -f
# ... Do stuff ...
echo "Please copy this line to your environment:"
echo "setenv MYVAR $myvar"