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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:04:38+00:00 2026-06-02T02:04:38+00:00

I am writing a shell script that outputs selected MySql table data as an

  • 0

I am writing a shell script that outputs selected MySql table data as an exercise. Searches using my key words turn up only how to print out an entire MySql table, doing this in a different language and irrelevant questions.

My questions:

1) If possible, how do I reference individual attributes of a certain row from the results (like iterating when through rows with PHP results)?

2) Which of the two ways below, if either, makes the most sense for this purpose? Neither works quite the way I would like at the moment.


MYSQL="mysql -u$db_user -p$db_passwd $db_name -Nbe"

A)

RESULT=`$MYSQL "select * from $table_name where can_auto_check='yes';"`
for UNIQUEID in $RESULT
do
    echo "selected: $client $desc "
    someFunction $client $anothervariable
done

B)

$MYSQL "select * from $table_name where can_auto_check='yes';" \
| while read client anothervariable;
do
    echo "selected: $client $desc "
    someFunction $client $anothervariable
done

It is possible I am wording my searches incorrectly; if that is the case, I would appreciate if someone would nudge me in the right direction.

Thank you.

EDIT: possible lead.. something to do with awk ‘{print $1″ “$2 }’ maybe. but for every line.

Final format = ” mkdir -p /net/$SERVER/$CLIENT/$DESC/someFiles “

  • 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-02T02:04:39+00:00Added an answer on June 2, 2026 at 2:04 am

    Not bad, but less code means fewer chances for errors. Unfortunately, I can’t test my edit, as I don’t have mySQL available. Hopefully you’ll get the idea. (or others are welcome to test and edit this post).

    # unless you need to use ALL_CLIENTS and DESC_FOR_CLIENT later.
    #hidden ALL_CLIENTS=
    
    for CLIENT in $($MYSQL "select distinct client from $table_name where can_auto_check='yes'")
    do
        #hidden DESC_FOR_CLIENT=
        for DESC in $($MYSQL  "select desc from $table_name where client='$CLIENT'")
        do
             someFunction $CLIENT $DESC
        done
    done
    

    If any of your values for CLIENT or DESC_FOR_CLIENT windup having spaces in them, you will need to quote your usage values like "$CLIENT" .

    One other note: back-ticks for command substitution have been deprecated since at least 1995 (unless you’re using orginal unix bourne shell or csh, maybe ash, and few other more obscure shell). Bash and ksh no need. use $( .. cmd ...) for your cmd-substitution.

    Good luck.

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

Sidebar

Related Questions

I'm writing a shell script that outputs all untranslated strings from gettext .po file,
I'm writing a bit of code to run a shell script using process that
I'm writing a shell script that before running needs to check that system Perl
I am writing a POSIX shell script that may or may not receive input
I'm writing a shell script (tcsh) that is supposed to received 3 parameters or
I'm writing a shell script. A variable will have a url that will look
I'm writing a shell script that makes sure my DNS server is looking. Here's
I'm writing a shell script that looks like this: for i in $ACTIONS_DIR/* do
I am writing a simple shell script that fetches output from one command and
I writing a ksh shell script and I have long comma separated string that

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.