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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:59:07+00:00 2026-05-26T23:59:07+00:00

I am trying to nest multiple if-statements as the following: #!/bin/bash # start_server.sh #

  • 0

I am trying to nest multiple if-statements as the following:

#!/bin/bash
# start_server.sh
# 
# Use this script to start the MarketDataTransmitter.
#
# Usage: ./start_server.sh    Starts the MarketDataTransmitter.

reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
cyan=$(tput setaf 6)
echo
directory=$(ls -l)
check_exist=$(awk -v a="$directory" -v b="MarketDataTransmitter" 'BEGIN { print index(a, b) }')
if [ "$check_exist" = "0" ]; then
  # MarketDataTransmitter is not present.
  echo "${red}[ERROR]${reset} Could not start ${yellow}MarketDataTransmitter${reset}."
  echo "        ${yellow}MarketDataTransmitter${reset} could not be found."
else
  # MarketDataTransmitter is present.
  processes=$(ps -ef | grep -i "MarketDataTransmitter" | grep -v "grep" | grep -v "bash" | awk '{ print $8 }')
  check_run=$(awk -v a="$processes" -v b="MarketDataTransmitter" 'BEGIN { print index(a, b) }')
  if [ "$check_run" = "0" ]; then
    # MarketDataTransmitter is not running.
    if [ -e "srv.log" ]; then
      if [ -s "srv.log" ]; then
        if [ -d "logs" ]; then
          date_time=$(date '+%Y%m%d_%H_%M_%S')
          new_log_name="srv_$date_time.log"
          mv srv.log $new_log_name
          mv $new_log_name logs
        else
          mkdir logs
          date_time=$(date '+%Y%m%d_%H_%M_%S')
          new_log_name="srv_$date_time.log"
          mv srv.log $new_log_name
          mv $new_log_name logs
        fi
      else
        echo "srv.log is empty and will be removed."
        rm -rf srv.log
      fi
    else
      # No srv.log but this is to start MarketDataTransmitter so we can ignore.
    fi
    ./MarketDataTransmitter > srv.log &
    echo "${yellow}MarketDataTransmitter${reset} has been started."
  else
    # MarketDataTransmitter is already running.
    echo "${red}[ERROR]${reset} Could not start ${yellow}MarketDataTransmitter${reset}."
    echo "        ${yellow}MarketDataTransmitter${reset} is already running."
  fi
fi
echo

However it is giving me syntax complaints saying:

syntax error near unexpected token `fi’

on the very last ‘fi’

Does anyone know why?

Thanks.

[EDIT] Full code has been posted.

  • 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-26T23:59:08+00:00Added an answer on May 26, 2026 at 11:59 pm

    You have an else statement and fi statement with nothing between them on lines 44-46 (just a comment between them). In bash, you need to have some statement in the body of that else block, or take the else block out.

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

Sidebar

Related Questions

I am trying to nest in SQL statements that are trying to pull data
I'm trying to nest a couple let statements, but I'm getting syntax errors that
How do I nest IF statements in Excel 2010? I found my inspiration trying
Trying to nest newly created DOM nodes 3 levels deep. I'm using the following
I am trying nest a Location directive inside a virtual host config like this:
I'm trying to nest this %h1 Admin Menu %small logged in as: #{session[:username]} To
I've been trying to nest sets within sets but to no avail. This concept
I'm trying to nest a form within another using submit_to_remote but it does a
I've spent hours trying to get my code to work, its a rats nest
Trying to set RowHeight like this(in code): dgvTruckAvail.RowTemplate.Height = 48; Doesnt' work. I also

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.