Run SQL thru shell script: how to get a new line when run sql query?

Hi, this's Pom. I'm quite a new one for shell script but I have to do sql on shell script to query some information from database.

I found a concern to get a new line...When I run my script, it retrieves all data as wondering but it's shown in one line :frowning:

What should I do? I'm not sure that I did set the statements correctly.
Please kindly to suggest me ;(

Thanks~

============================================
Code:

#!/bin/bash
 
suc_num=`$PATH/sqlplus -s xx/yyy@service_name << !
set echo off
set feedback off
set heading off
set pagesize 0
set newpage 0
set wrap on
@success.sql
commit;
exit;
!`
 
echo $suc_num

=====================================================
Result: (Should have 3 columns: DateTime[yyyy-mm-dd hh]|The Number|ElementName)

2012-06-17 10 2 HLR_DUMMY 2012-06-17 11 1 HLR_DUMMY 2012-06-17 12 2 HLR_DUMMY 2012-06-17 15 1 HLR_DUMMY 2012-06-17 17 1 HLR_DUMMY 2012-06-17 00 102 aaa1 2012
-06-17 01 33 aaa1 2012-06-17 02 20 aaa1 2012-06-17 03 344 aaa1 2012-06-17 04 10 aaa1 2012-06-17 05 19 aaa1 2012-06-17 06 35 aaa1 2012-06-17 07 76 aaa1 2012-06-17 08 222 aaa1 2012-06-17 09 425 aaa1 2012-06-17 10 4211 aaa1 2012-06-17 11 552 aaa1 2012-06-17 12 994 aaa1 2012-06-17 13 1077 aaa1 2012-06-17 14 844 aaa1 2012-06-17 15 779 aaa1 2012-06-17 16 892 aaa1 2012-06-17 17 932 aaa1
echo "$suc_num"

Put double quotes around the variable. Hope this will resolve your issue.

1 Like

Oh gosh!!! O[]O!!!Really easy!

A million thanks, prvin27. It's okay now. :))