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 7847105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:47:19+00:00 2026-06-02T17:47:19+00:00

I usually source a *.sh file in a bash terminal on linux like this

  • 0

I usually source a *.sh file in a bash terminal on linux like this

. ./myscript.sh

before running a command line PHP script so i can access exported environment variables using PHP’s $_SERVER super global.

Is it possible to source the sh file from within the PHP script itself to then access the variables it exports?

I’ve tried all sorts with no success. I’ve tried

system('. ./myscript.sh')
system('sh ./myscript.sh')

exec('. ./myscript.sh')
exec('sh ./myscript.sh')

shell_exec('. ./myscript.sh')
shell_exec('sh ./myscript.sh')

using these, the exported vars do not appear in $_SERVER.

Any ideas?

  • 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-02T17:47:21+00:00Added an answer on June 2, 2026 at 5:47 pm

    Your variables aren’t available because the shell that they existed in has exited. You need to execute PHP from within the same shell in order to get its vars.

    Either edit myscript.sh to launch the PHP script after setting the vars:

    export VAR1=1
    export VAR2=2
    php -f /path/to/script.php
    

    Or write another wrapper script that sources your file and then launches PHP from the same shell:

    . ./myscript.sh
    php -f /path/to/script.php
    

    Edit: Or just run your script like this:

    . ./myscript.sh && php -f /path/to/script.php
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hard time reading open source file download pages like this http://rubyforge.org/frs/?group_id=167
From time to time a source file somehow gets two class files, like this:
This is for C++. Usually we have our function declaration in header file and
I am running Windows 7, and am not usually a developer in this setting,
I usually use Visual Studio Team System 2008 Source Control Explorer with TFS, but
Current static source analysis tools for C# (or other .NET languages) usually operate on
Usually I was doing something like that (just a example): using (Stream xmlStream =
I have an object file, which I'd like to make into a Mach-O binary(I'm
I was wondering how people usually navigate through large projects with several source files
We have a certain binary file in our git repository. Usually it's around 2MB

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.