Reputation: 87
I get the following error when I try to set linux environment variables in tclsh
% exec export a=1
couldn't execute "export": no such file or directory
%
Is there a way to execute linux system commands in tclsh?
Upvotes: 0
Views: 79
Reputation: 137627
Shell builtins aren't independent programs, so you conceptually need to run them like this:
# Maybe bash instead of sh
exec sh -c "export a=1"
But on it's own like that, that's useless. The export
builtin says to make the shell variable available as an environment variable to subprocesses... but that fragment isn't launching any! (Doing a bare cd
or umask
in a shell subprocess isn't much more useful either.) You have to either launch something from within the same process that uses the inheritable state change, or move the state change up to the parent process (Tcl).
exec sh -c "export a=1; myProgram"
# Tcl manages environment variables through the env global array
set env(a) 1
exec myProgram
Upvotes: 3