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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:44:36+00:00 2026-06-03T03:44:36+00:00

I am a noob when it comes to the Shell This block should work,

  • 0

I am a noob when it comes to the Shell

This block should work, but it doesn’t

     #!/bin/bash 
     # LOCAL CONFIGURATION SETTINGS - DB_CONFIG is a "fake" associative array
     #----------------------------------------------------------------------------------
     DB_CONFIG=(
        "DB_NAME=>"
        "DB_USER=>root"
        "DB_PASSWORD=>root"
        "DB_HOST=>127.0.0.1"
        "DB_CHARSET=>utf8"
        "DB_COLLATE=>"
     );

     for prop in ${DB_CONFIG[@]} ; do
     key=${prop%%=>*}
     value=${prop##*=>}
     echo $key;
     if[["$key" == "DB_HOST"]] then 
           db_host="$value"

     if[["$key" == "DB_PASSWORD"]] then  
           db_password="$value"

     done;


     # now set the mysql_conn string with the vars above.
     MYSQL_CON="/Applications/MAMP/Library/bin/mysql --host=$db_host -uroot -$db_password"
     exit;
     REPO='http://svn.wp-plugins.org/'

The problem is how to check the condition if $key == 'DB_HOST' I just can’t figure out the syntax of the expression. I have look into how to do it, but on my mac ( running bash 3.2 ) if complains of syntax errors.

  • 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-03T03:44:39+00:00Added an answer on June 3, 2026 at 3:44 am

    This should work for you:

    DB_CONFIG=(
      "DB_NAME=>"
      "DB_USER=>root"
      "DB_PASSWORD=>root"
      "DB_HOST=>127.0.0.1"
      "DB_CHARSET=>utf8"
      "DB_COLLATE=>"
    );  
    
    for prop in ${DB_CONFIG[@]}; do
      key=${prop%%=>*}
      value=${prop##*=>}
    
      if [[ "$key" == "DB_HOST" ]]; then 
           db_host="$value"
      elif [[ "$key" == "DB_PASSWORD" ]]; then  
           db_password="$value"
      fi  
    done
    
    echo "$db_host" "$db_password"
    

    You were missing the space after [[ and before ]]. You were also missing your fi s, which correspond to close brace in C or Java, and are required by bash. Additionally, if-statements require a ; after a conditional test.

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

Sidebar

Related Questions

I'm a total noob when it comes to C but i found this curl
I guess this is a noob question, but here it comes: I have a
I'm a bit of a noob when it comes to HTML and CSS but
I'm a total noob when it comes to jQuery but I am trying to
I'm a noob when it comes to mongodb and nosql as a total, but
I am super noob when comes to javascipt, how come click() isn't working? This
I am bit of a noob when it comes to this topic. I am
I'm a noob but I made my application work beautifully using python manage.py runserver
I'm very noob when it comes to ASP.NET MVC. I'm looking at the starter
I am a complete Noob when it comes to GIT. I have been just

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.