Reputation: 3215
I am working on a remote server through putty and am trying to set certain environment variables throught something like this
#!/bin/bash
VAR="SOME VALUE"
export $VAR
when I exit the script and run echo on $VAR, I am given a blank line. could you please suggest a way around this.
Upvotes: 6
Views: 3797
Reputation: 20970
First you need to export VAR, rather than $VAR.
Plus, I think, you are trying to execute the script from your shell as
./initVars.sh # or whatever is your script name...
You should rather source it as
source ./initVars.sh # OR
. ./initVars.sh # Note the leading '.' which serves as short-hand for source.
You can put it in your .bashrc.
Upvotes: 10
Reputation: 7411
Two problems. First, it's just export VAR
. Second, $VAR
will only be available to your script and child processes, not to the parent shell. You can source it like . ./yourscript.sh
from the shell if you want $VAR
to be set for that shell.
Upvotes: 0