Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting environment variables from within TCL script

I was creating a Tcl script which will allow me to automate the installation of software. But the problem I am running into is that the software needs some environment variables set beforehand and I was wondering if its possible to set environment variables inside of the tcl script.

I was going to try exec /bin/sh -c "source /path/to/.bash_profile but that would create a shell script and source the variables into there and the tcl script wont pick it up then.

Can anyone give any other ideas?

like image 270
Attiq Avatar asked Apr 17 '15 18:04

Attiq


People also ask

How do I set environment variables in Tcl?

Show activity on this post. And then any child process has the variable foo in its environment. If you want to put environment variables in a central file (i.e. . bash_profile ) so that other programs can source them, then it should be pretty easy to get Tcl to parse that file and set the variables in the env array.

How are environment variables used in Tcl script?

Environment variables are available to Tcl scripts in a global associative array env . The index into env is the name of the environment variable. The command puts "$env(PATH)" would print the contents of the PATH environment variable.

How do I set environment variable in Tcl Mcq?

In side tcl script, you can simply do setenv as, setenv AUTOTEST="/auto/isbutest/frt" . if you want to set a variable, use set VARNAME "/auto/isbutest/frt" . if you want to get any environment variable, use $::env(AUTOTEST) .

What does :: mean in Tcl?

namespace tail stringReturns the simple name at the end of a qualified string. Qualifiers are namespace names separated by double colons (::). For the string ::foo::bar::x, this command returns x, and for :: it returns an empty string. This command is the complement of the namespace qualifiers command.


1 Answers

In Tcl you have the global env array:

set ::env(foo) bar

And then any child process has the variable foo in its environment.

If you want to put environment variables in a central file (i.e. .bash_profile) so that other programs can source them, then it should be pretty easy to get Tcl to parse that file and set the variables in the env array.

like image 153
glenn jackman Avatar answered Nov 06 '22 22:11

glenn jackman