Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8830553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:07:13+00:00 2026-06-14T08:07:13+00:00

I have a simple bash script: #!/bin/bash JAVA_HOME=/usr EC2_HOME=~/ec2-api echo $EC2_HOME export PATH=$PATH:$EC2_HOME/bin I

  • 0

I have a simple bash script:

#!/bin/bash
JAVA_HOME=/usr
EC2_HOME=~/ec2-api
echo $EC2_HOME
export PATH=$PATH:$EC2_HOME/bin

I run the script like so

$ ./ec2
/Users/user/ec2-api

The script runs and produces the correct output.

However, when I now try to access the EC2_HOME variable, I get nothing out:

$ echo $EC2_HOME

I get a blank string back. What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T08:07:15+00:00Added an answer on June 14, 2026 at 8:07 am

    Do either of the following instead:

    source ec2
    

    or

    . ec2
    

    (note the . notation is just a shortcut for source)

    Explanation:

    • This is because ./ec2 actually spawns a subshell from your current shell to execute the script, and subshells cannot affect the environment of the parent shell from which it spawned.
    • Thus, EC2_HOME does get set to /Users/user/ec2-api correctly in the subshell (and similarly the PATH environment variable is updated and exported correctly in the subshell as well), but those changes won’t propagate back to your parent shell.
    • Using source runs the script directly in the current shell without spawning a subshell, so the changes made will persist.
    • (A note on export: export is used to tell new shells spawned from the current shell to use the variables exported from the current shell. So for any variables you would only use in the current shell, they need not be exported.)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple script which is behaving un-expectedly. path='/usr/local/bin/new_script' content='#!/bin/bash\nls' sudo echo -e
I have a simple test bash script which looks like that: #!/bin/bash cmd=rsync -rv
I have a crontab that looks like: SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root HOME=/ 0-59 * *
I have a very simple script: #!/bin/bash gnuplot << EOF set term postscript portrait
I am trying a simple shell script like the following: #!/bin/bash up_cap=$( cat result.txt
Possible Duplicate: grep loses coloring when run from bash script I have a simple
I have a simple script named example : #!/bin/sh echo $'${1}' Please note that
I have the following script sample: #!/bin/bash # Aborts the script on simple command
I have simple bash script: #!/bin/sh column=${1:-1} awk ' {colawk='$column'+2; print $colawk}' awk '(x=4;
For example, i have this simple bash script: #!/bin/sh cd $1; And this cocoa

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.