How to use all the Unix environment variables?

▼魔方 西西 提交于 2019-12-11 07:40:52

问题


Using Java (JSch API) I am trying to execute an Unix command on a remote machine. Now, to successfully execute this command I need to use all the environment variables already set on the remote box.

I can use export <variable> command to set the variables on runtime. But as the number of such variables is quite large I am wondering if there is any better way to use the variables in runtime.

Can anyone help please or should I explain a bit more?


回答1:


You can save variables into a file:

set > /tmp/vars
echo "A=120" >> /tmp/vars

and then "import" the variables with dot in a script like this:

set -a
. /tmp/vars
mycommand



回答2:


The work around I found was to use

set | mycommand

Set will manually call the initialization process and it will add environment variables into the scope.

JSch calls bash with -c. This causes .bashrc not to be initialized inside of the bash scope. Set will read the .bashrc file and other config files.



来源:https://stackoverflow.com/questions/21107520/how-to-use-all-the-unix-environment-variables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!