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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:26:58+00:00 2026-05-18T11:26:58+00:00

I am a newbie with shell scripting so need a few ideas on parsing

  • 0

I am a newbie with shell scripting so need a few ideas on parsing a PHP file using a shell script.

Ours is a PHP project and I am improving our shell script which is used to upload code to production server.

There is one PHP config file production.settings.php which needs to be read during upload, for a few constants –

BASE_PATH (path to project root on prod server)
db_host, db_name etc. (database settings of prod database – to be used for taking a backup of the database before upload)

Question

  • How to read the value of the constants?

    They are defined like this:

    define("BASE_PATH","/path/to/project/root");
    
  • How to read the first uncommented value of the constant?
    Note – The constant may be defined more than once in the same file (let’s assume the possibilty – this may happen by mistake or there may be commented instances of the line)

So far I am only able to get the number of lines containing the string define("BASE_PATH" using grep in my shell script –

cd ..
PROJECT_ROOT=$PWD
result= grep -ic 'define("BASE_PATH",' $PROJECT_ROOT'/config/main.settings.php'
echo "see"$result
  • Is this method of parsing good enough or a yml file would be better? Is there any shell command/snippet for doing this so that I can get the result by writing lesser amount of code?

Updates
Check my other questions for more details on this:-
Manipulating an array (printed by php-cli) in shell script,
Assigning values printed by PHP CLI to shell variables,
Initiating dynamic variables (variable variables) in bash shell script

  • 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-05-18T11:26:59+00:00Added an answer on May 18, 2026 at 11:26 am

    just do it using the php, then call your shell script to invoke the php script.

    Assuming you have your bunch of defines defined in defs.php:

    define('NAME', 'JOHN');
    define('HOBBY', 'FISHING');
    

    then create a php script get_defs.php:

    require_once 'defs.php';
    $const = get_defined_constants(true);
    foreach($const['user'] as $k => $v) {
       echo "export $k=$v";
    }
    

    then in your shell script, run it like so:

    `php get_defs.php`
    

    What happen is, get_defs.php will output bunch of export KEY=VALUE, then shell will run those commands outputted by your php get_defs.php.

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

Sidebar

Related Questions

php newbie here..I need some PHP help ideas/examples on how to import data from
I am a newbie for shell script. I noticed that for command like: tar
I am a shell script newbie. I want to know the difference between ${var%pattern}
Java Newbie here. I have a JFrame that I added to my netbeans project,
I'm a newbie to pgsql. I have few questionss on it: 1) I know
I am a newbie to VBS scripting. Thanks for all your comments! I fixed
Newbie question. After I have written the Android App (easy part) I need to
I'm a newbie and I'm trying to write a python script to build rpm
newbie here. This is an iPhone utility project. First things first. I have a
LaTeX newbie here. I need to set background color for all my \subsection titles.

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.