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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:32:36+00:00 2026-05-25T13:32:36+00:00

As you know in Drupal there is a settings.php file with database connector. $db_url

  • 0

As you know in Drupal there is a settings.php file with database connector.
$db_url = ‘mysql://username:password@localhost/databasename’;
I would like a shell script to extract the string which is the ‘databasename’ and echo it.

Help is much appreciated.
Thanks

  • 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-25T13:32:37+00:00Added an answer on May 25, 2026 at 1:32 pm

    You can use:

    #!/bin/bash
    dbname=`grep db_url settings.php | cut -d "/" -f 4`
    echo ${dbname%"';"}
    

    The first line searches settings.php for db_url, and then pipes that into cut that removes all text before the first 3 slashes. Finally the last ‘: is removed from the end of the variable and it is echoed. This code is very dependant on the format of the url, it relies on the fact that there will always be 3 slashes before the database name.

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

Sidebar

Related Questions

I'm new to Drupal and I would like to know if there are some
I'm building a Drupal theme up and want to know if there is a
Does anyone know if there's a decent image crop module around for Drupal 7?
Is there a SQL Server Provider for Drupal? I know that there is a
I want to know if there's any module(s) that would allow any OG admin
I want to connect drupal 6.X verstion with oracle database. So, Is there any
In my Drupal rules settings I don't have Execute custom PHP code option anymore.
I would like to know is there any module for exporting all the content
In Drupal 6, I would do the following to get images in my node--articles.tpl.php
Anyone know how to use Google Analytics for a Drupal-powered company intranet site behind

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.