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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:25:45+00:00 2026-05-14T00:25:45+00:00

When our server comes up we need to check a file to see how

  • 0

When our server comes up we need to check a file to see how the server is configured.

We want to search for the following string inside our /etc/aws/hosts.conf file:

MYSQL_ROLE=master

Then, we want to test whether that string exists and use an if/else statement to run one of two options depending on whether the string exists or not.

What is the BASH syntax for the if statement?

if [ ????? ]; then
  #do one thing
else
  #do another thing
fi
  • 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-14T00:25:46+00:00Added an answer on May 14, 2026 at 12:25 am

    From grep --help, but also see man grep:

    Exit status is 0 if any line was selected, 1 otherwise;
    if any error occurs and -q was not given, the exit status is 2.

    if grep --quiet MYSQL_ROLE=master /etc/aws/hosts.conf; then
      echo exists
    else
      echo not found
    fi
    

    You may want to use a more specific regex, such as ^MYSQL_ROLE=master$, to avoid that string in comments, names that merely start with “master”, etc.

    This works because the if takes a command and runs it, and uses the return value of that command to decide how to proceed, with zero meaning true and non-zero meaning false—the same as how other return codes are interpreted by the shell, and the opposite of a language like C.

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

Sidebar

Related Questions

I package our server releases into zip files using a batch file (Windows), running
Our git server will be local, but we want an server where our local
Our DB server fell, and we need to restore some of it's DB's. We
I need to check that our visitors are using HTTPS. In BasePage I check
We are trying to come up with our client and server standard and there
Our server application is listening on a port, and after a period of time
Our server already has symantic anti-virus with autoprotect enabled w/ regular scans and updates.
If our server (running on a device) starts before a DHCP lease had been
I'm creating an ASP.NET web application to schedule tasks on our server from a
Our Tfs server (Tfs2008) has smtp server installed. But we could not make Tfs

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.