Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can seem to export environment variable from bash script

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.

like image 507
sidharth sharma Avatar asked Nov 06 '12 06:11

sidharth sharma


1 Answers

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.

like image 148
anishsane Avatar answered Sep 30 '22 04:09

anishsane