sid*_*rma 5 bash environment-variables variable-assignment
我正在通过putty在远程服务器上工作,并试图通过这样的方式设置某些环境变量
#!/bin/bash
VAR="SOME VALUE"
export $VAR
Run Code Online (Sandbox Code Playgroud)
当我退出脚本并在$ VAR上运行echo时,我得到一个空行.你能不能就这个问题提出建议.
首先,您需要导出VAR,而不是$ VAR.
另外,我认为,您正尝试从shell执行脚本
./initVars.sh # or whatever is your script name...
Run Code Online (Sandbox Code Playgroud)
你应该把它作为源代码
source ./initVars.sh # OR
. ./initVars.sh # Note the leading '.' which serves as short-hand for source.
Run Code Online (Sandbox Code Playgroud)
你可以把它放在你的.bashrc中.