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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:31:16+00:00 2026-05-30T00:31:16+00:00

i run this script from the command line: check_databse_exist=`mysql -u root –password=root -Bse ‘show

  • 0

i run this script from the command line:

check_databse_exist=`mysql -u root --password=root -Bse 'show databases' | egrep -v 'information_schema|mysql'`
for db in $check_databse_exist; do
if [ "$db" == "test_traffic" ] ; then
   exist=1
fi
done

if [ $exist -eq 1 ] ; then
   #do other stuff
fi

exit 0

why is it giving:

 [: 16: jobeet: unexpected operator
 [: 16: jobeet_test: unexpected operator
 [: 16: landpage_db: unexpected operator
 [: 16: my_db: unexpected operator
 [: 16: symfony2: unexpected operator
 ./cibuild: 24: [0: not found

i just want to loop and if found set exist = 1
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-30T00:31:18+00:00Added an answer on May 30, 2026 at 12:31 am
    if [$exist == 1] ; then
    

    Due to a shell scripting quirk you need spaces around the square brackets. They’re not optional.

    if [ $exist == 1 ]; then
    

    For what it’s worth, you could refactor this a bit if you merely want to check for the existence of one table, and don’t otherwise need $check_databse_exist. The idea would be to to replace the for loop with a grep.

    if mysql -u root --password=root -Bse 'show databases' | grep -qw test_traffic; then
        # Database exists.
    fi
    

    grep -q produces no output, it merely returns success or failure. grep -w is optional but a good practice; it prevents a table like test_traffic2 from matching.

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

Sidebar

Related Questions

In Python one can say this: python script.py from the command line and receive
I can run this command from the command line without any problem (the validation
I can run my script just fine from the command line: php test.php and
I am following this tutorial and I've run the command ruby script\server and successfully
I'd like to prevent multiple instances of the same long-running python command-line script from
I'm writing this Perl script that gets two command line arguments: a directory and
I'm trying to run this script: import re, os def build_pool(cwd): global xtn_pool, file_pool
Can anyone please tell me how do I make this script run in IE
I have this script and when i try to run it, it just says
I have tryed to run this code in my console: script/plugin install git://github.com/apotonick/cells.git ...but

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.