关于tclsh 中环境变量(env)的使用
来源:互联网 发布:高考状元笔记淘宝 编辑:程序博客网 时间:2024/06/07 20:57
有一个脚本调用:shell script 调用tcl script
shell script -> tclsh
这里shell脚本执行时有很多环境变量,在tclsh如何获取?
其实tclsh已经很好地继承了调用它的shell 脚本中的环境变量:
global 的变量env,其实是一个数组:
% parray env
env(DISPLAY) = localhost:10.0
env(HOME) = /home/windriver
env(LANG) = en_US.UTF-8
env(LESSCLOSE) = /usr/bin/lesspipe %s %s
env(LESSOPEN) = | /usr/bin/lesspipe %s
env(LOGNAME) = windriver
env(PWD) = /home/windriver
env(SHELL) = /bin/bash
env(_) = /usr/bin/tclsh
如果在tcl脚本中修改了env 中某个环境变量,tclsh 脚本中的相应的环境变量也随之改变,如果在tclsh 中调用了别的脚本或者exec 命令,则sub-process会继承tclsh脚本中的环境变量。
曾经试图通过tclsh脚本去修改shell 脚本中的env 环境变量,因为这个shell脚本会使用环境变量去调用其他的脚本,想让这个环境变量在tclsh 脚本中被更改并传递给shell 脚本。
使用了以下方法:
set env(MY_VAR) Modification.
或者
exec sh -c "export MY_VAR=IModifiedThis!"
但实践表明:不能从sub-process 中去修改parent process中的环境变量。
从tcl/tk 官方得到一些信息(http://www2.tcl.tk/706):
Many times people come looking for a way to set an environment variable in such a way as to influence a parent process. This is, in generally, rather difficult to do. One generally solves this problem via cooperation - in some way communicating back to the parent process that it needs to set the variable itself.
For example, you could write out to stdout the value you want the parent to get, then have the parent process read the child's stdout and put the value into the variable.Or you could write out a text file containing variable names and values (perhaps in shell format) then have the parent read in the values and take the action. Or you could set up some sort of socket, pipe, etc. and communciate that way.But at least in Unix like systems, a child process DOES NOT HAVE WRITE ACCESS to the process space of the parent. Period .CL puts it more starkly: "... you can't change the value of an environment variable in another already running process", according to the authoritative Unix Programming FAQ [1] (why? Among other reasons, security considerations prohibit such an operation). However, as Larry hints above, there are ways to change the question slightly to give effective control over ...See "Setting environment variables with a script" for more.- 关于tclsh 中环境变量(env)的使用
- 关于linux操作系统的环境变量(env)
- 关于linux操作系统的环境变量(env)
- CGI的环境变量(env)
- shell中,用set命令可显示全部的变量(包括环境变量和自定义变量),env只显示环境变量
- 生成自己的 tclsh
- u-boot中env命令的使用
- 关于env的说明
- 环境变量env
- 关于Lumen / Laravel .env 文件中的环境变量是如何生效的
- 获取tomcat中web.xml中定义的环境变量(env-entry)
- Linux env --显示当前用户的环境变量
- 设置环境变量配置的简单方法.env
- 修改PATH环境变量及export,readonly,env,unset命令的使用
- /usr/bin/env的使用
- Linux中环境变量三命令:set、env、export浅析
- 如何使用脚本set-env来设置环境变量[转]
- Perl中的环境变量%ENV
- 最大公约数(递归法)
- strlen(str)与str.length()
- android Activity的生命周期于四种加载状态
- cookie不能获取自己设置的,只能获取系统的名字为JSESSIONID的cookie的解决办法
- MVC的含义,并说明其各部分通常使用的Java技术
- 关于tclsh 中环境变量(env)的使用
- Exception类实现(12)
- android 获取手机信息,并且将结果post到服务器和保存到本地
- [LeetCode] Subsets
- linux手工配置ip
- jquery : 获取可视窗体高度
- Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient va
- QQ登陆画面的最小化显示机制(使程序不在任务栏显示)
- 设计模式:模板方法模式(8)C++版