help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Loop on mysql output with bash


From: Greg Wooledge
Subject: Re: [Help-bash] Loop on mysql output with bash
Date: Tue, 13 Mar 2018 09:05:41 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Tue, Mar 13, 2018 at 09:49:50AM +0100, Boubaker Idir wrote:
> I want to do a select from my database and to put it in a json file

I strongly recommend Anything But Bash.

You want a language that can connect to whatever database this is...

> #!/bin/bash
> #declare array=$(mysql -u root -pPassword -s -N #<<QUERY_INPUT

... to mysql, and retrieve results into some kind of data structure
(dictionary, list, hash table, whatever).  And you also want a language
that can render that data structure (dictionary, etc.) into JSON format.

Bash sucks at both of those.  For the JSON piece, there's jq and other
external utilities that you can install, but there is NOTHING you can
do to retrieve SQL results and safely separate them into bash variables
or associative array elements.

https://mywiki.wooledge.org/BashWeaknesses



reply via email to

[Prev in Thread] Current Thread [Next in Thread]