Skip to main content
Post Merged (destination) from unix.stackexchange.com/questions/139447/…
Make title more generic to use as dupe target since this is not bash-specific
Link
Michael Homer
  • 78.9k
  • 17
  • 221
  • 239

How can I make environment variables "exported" in a bashshell script stick around?

edited tags
Link
Gilles 'SO- stop being evil'
  • 866.5k
  • 205
  • 1.8k
  • 2.3k
Tweeted twitter.com/#!/StackUnix/status/163040831320756226
added 4 characters in body
Source Link
Kevin
  • 41.8k
  • 17
  • 91
  • 113

I have multiple Amazon EC2 accounts and want to quickly be able to switch variables, such as $EC2_HOME$EC2_HOME, using a script.

I have have a shell script set up like this:

#!/bin/sh export EC2_HOME=/home/me/.ec2 echo $EC2_HOME 

When I run the script I know that EC2_HOMEEC2_HOME is set, but I thought that using export would make the variable stick around after the script completed. It does not, as running echo $EC_HOME does not show anything.

I know this must be very rudimentary Linux scripting knowledge, but I don't know it. I tried looking for related questions without luck - so my apologies if this is a duplicate.

I have multiple Amazon EC2 accounts and want to quickly be able to switch variables, such as $EC2_HOME, using a script.

I have have a shell script set up like this:

#!/bin/sh export EC2_HOME=/home/me/.ec2 echo $EC2_HOME 

When I run the script I know that EC2_HOME is set, but I thought that using export would make the variable stick around after the script completed. It does not, as running echo $EC_HOME does not show anything.

I know this must be very rudimentary Linux scripting knowledge, but I don't know it. I tried looking for related questions without luck - so my apologies if this is a duplicate.

I have multiple Amazon EC2 accounts and want to quickly be able to switch variables, such as $EC2_HOME, using a script.

I have have a shell script set up like this:

#!/bin/sh export EC2_HOME=/home/me/.ec2 echo $EC2_HOME 

When I run the script I know that EC2_HOME is set, but I thought that using export would make the variable stick around after the script completed. It does not, as running echo $EC_HOME does not show anything.

I know this must be very rudimentary Linux scripting knowledge, but I don't know it. I tried looking for related questions without luck - so my apologies if this is a duplicate.

added 5 characters in body
Source Link
cwd
  • 47.1k
  • 73
  • 156
  • 172
Loading
Source Link
cwd
  • 47.1k
  • 73
  • 156
  • 172
Loading