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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:53:32+00:00 2026-06-18T20:53:32+00:00

In shell scripting I am retrieving data from database and trying to print it,

  • 0

In shell scripting I am retrieving data from database and trying to print it, but it does not print as I am trying to do it.

My code is:

 mysql -uroot -proot -Dproject_ivr_db -rN --execute "SELECT Regular FROM 
 Fee_MSc WHERE Fee_Type='Total:'" | while read value

 x=1

 do
       echo "V,FeeRegular_$y=$value"
       let "y+=1"
 done

 echo "V,fee_msc_regular="for students on regular basis admission fee 
 including other charges is $FeeRegular_1 and semester fee is $FeeRegular_2""

Output is:

 V,FeeRegular_1=12590
 V,FeeRegular_2=12850

 V,fee_msc_regular=for students on regular basis admission fee including other
 charges is and semester fee is   

It does not print the values of $FeeRegular_1 and $FeeRegular_2 in the string output.

How can I get the values of these variables in the output string?

  • 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-18T20:53:33+00:00Added an answer on June 18, 2026 at 8:53 pm

    Assuming a bash-like shell, the variables that you are looking to create do not exist when the while-loop exists. This is because you are piping the results and creating a subshell with a new environment, which is not shared with the parent shell.

    You can restructure your loop to be a for-loop using process substitution. Rather than attempting to append a number to the end of a variable name, use an array.

    #!/bin/bash
    i=0
    for value in $(mysql -u{$db_user} -p${db_pass} -D${db_name} -rN --execute "
        SELECT Regular FROM Fee_MSc WHERE Fee_Type='Total:' ")
    do
        FeeRegular[$i]=${value}
        echo "FeeRegular[$i]=${FeeRegular[$i]}"
        let "i+=1"
    done
    echo "Found ${#FeeRegular[@]} fees..."
    echo "For students on regular basis admission fee including other charges is
    ${FeeRegular[1]} and semester fee is ${FeeRegular[2]}."
    

    I also recommend not using the root account for querying the database, increasing the strength of your passwords and not publishing them.

    Now… are you sure the results you are looking for are in rows 1 and 2? You’ve specified no order by clause in your query. But that’s a separate issue.

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

Sidebar

Related Questions

I am new at shell scripting and I am trying to read data from
HI I am not very good with linux shell scripting.I am trying following shell
I just started learning shell scripting. I'm trying to read from a file structured
I'm really new to UNIX/Shell Scripting I'm trying to extract disk usage from numerous
I'm trying to learn shell scripting, and I need to understand someone else's code.
I am a noob to shell scripting, I tried searching but could not find
How can I write data to a text file automatically by shell scripting in
What is the meaning for $! in shell or shell scripting? I am trying
This is a shell scripting question really, but relates to rails. I create a
I have a very basic understanding of shell scripting, but what I need to

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.