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

  • SEARCH
  • Home
  • 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 8093535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:31:23+00:00 2026-06-05T20:31:23+00:00

a.sh #! /bin/sh export x=/usr/local we can do source ./a in command-line. But I

  • 0

a.sh

#! /bin/sh
export x=/usr/local

we can do source ./a in command-line. But I need to do the export through shell script.

b.sh

#! /bin/sh
. ~/a.sh

no error… but $x in command-line will show nothing. So it didn’t get export.

Any idea how to make it work?


a.sh

#! /bin/sh
export x=/usr/local
-----------
admin@client: ./a.sh
admin@client: echo $x

admin@client:  <insert ....>
  • 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-05T20:31:24+00:00Added an answer on June 5, 2026 at 8:31 pm

    You can’t do an export through a shell script, because a shell script runs in a child shell process, and only children of the child shell would inherit the export.

    The reason for using source is to have the current shell execute the commands

    It’s very common to place export commands in a file such as .bashrc which a bash will source on startup (or similar files for other shells)

    Another idea is that you could create a shell script which generates an export command as it’s output:

    shell$ cat > script.sh
    #!/bin/sh
    echo export foo=bar
    ^D
    chmod u+x script.sh
    

    And then have the current shell execute that output

    shell$ `./script.sh`
    
    shell$ echo $foo
    bar
    
    shell$ /bin/sh
    $ echo $foo
    bar
    

    (note above that the invocation of the script is surrounded by backticks, to cause the shell to execute the output of the script)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a simple Linux Script this way export JAVA_HOME=/usr/local/jdk1.6.0_20 export PATH=/usr/local/jdk1.6.0_20/bin LIB_DIR=/home/praveen/lib export
My setup as below # export PATH=/usr/sbin:/usr/bin:/usr/local/bin:/usr/sfw/bin:/usr/ccs/bin # ./configure --prefix=/usr/local/nginx --user=webservd --group=webservd --with-http_stub_status_module --with-openssl=/usr/local/ssl/bin/openssl
When I do 'open .profile' in the terminal I have the following: export PATH=$PATH:/usr/local/git/bin
Can anyone tell me what's wrong in this code: #!/usr/local/bin/python import os import string,
I can't seem to figure out how to get his bash script working. #!/bin/bash
Written a bash script that generates thumbnails, not the nicest but it works: #!/bin/bash
While I try to set java path on ~./bashrc file i exported like: PATH=/usr/local/jdk1.6.0/bin
#!/bin/bash echo SCRIPT: $0 echo Enter Customer Order Ref (e.g. 100018) read P_CUST_ORDER_REF echo
#!/bin/bash echo 'first line' >foo.xml echo 'second line' >>foo.xml I am a total newbie
#!/bin/bash if test $# == 4; then echo $*; else echo args-error >&2; fi;

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.