I am querying an SQLite3 database like so:
input=$(-separator "," "SELECT field1,field2,field3 FROM table1")
and get this result:
Red,Yellow is a color,Blue
I need to insert this into an array, is there a way to set this result into an array in ksh without having the result return the field in quotation marks (which is not possible, as far as I know, from a query statement in sqlite)?
As in example:
#!/bin/ksh IFS=',' input=(Red,Yellow is a color,Blue) set -A array $input print ${array[@]} print ${array[0]} print ${array[1]} print ${array[2]}
If I run the above code I get this: $ Red Yellow Red Yellow
If you encapsulate the second element with quotation marks, like this:
#!/bin/ksh IFS=',' input=(Red,"Yellow is a color",Blue) set -A array $input print ${array[@]} print ${array[0]} print ${array[1]} print ${array[2]}
You get the proper result...
$ Red Yellow is a color Blue
The solution I need to know is, is there is a way I can set this array without the quotation marks in the second element. Or would a pre-process need to be done on the db result return to encapsulate the elements with quotation marks before inserting into the the array. If so, what would be a good starting place? I'd like to stay within ksh if I could.
echo
statement to print your data instead of the SQL command so we can also do it on our own systems.#!/bin/ksh
line (but withinput=…
instead of the SQL command because we don't have your database). What you've posted does not produce the output that you claim so you must have run different code.