[英]set environment variables with c-shell script
I want to set some environment variables with script. 我想用脚本设置一些环境变量。 I did something like that : 我做了这样的事情:
#!/bin/csh -f
setenv A "Hello"
setenv B "World"
source BlaBla
The script's name is for example "my_script" 脚本的名称例如是“ my_script”
So when I run : .my_script. 因此,当我运行时:.my_script。
There are no errors but if I try to use these environment variables in the shell like this : 没有错误,但是如果我尝试像这样在shell中使用这些环境变量:
echo $A
I get "A :Undefined variable." 我得到“ A:未定义的变量”。
What can I do to solve this ? 我该怎么解决?
Thanks. 谢谢。
Are you trying to use the variables in BlaBla
or in the shell that runs my_script
? 您是否要在BlaBla
或运行my_script
的外壳中使用变量?
They should be available in the context of the BlaBla
script as-written. 它们应在编写的BlaBla
脚本的上下文中可用。
If you want them available in the calling shell then you need to source my_script
instead of /path/to/my_script
which runs my_script
in a new shell that cannot set shell variables in the calling shell. 如果希望它们在调用shell中可用,则需要获取source my_script
而不是/path/to/my_script
source my_script
,后者将在无法在调用shell中设置shell变量的新shell中运行my_script
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.