Tabs missing in batch mode

Tabs missing in batch mode

am 24.04.2006 17:28:33 von fritz-bayer

Hi,

in a shell script of mine I'm executing a mysql SELECT in batch mode. I
want to use the return value for other sql statements.

The problem I'm facing is that the tabs, which seperate the columns
from each other, are missing in the output.

What am I doing wrong?

#!/bin/sh
QUERY="select id, i.handle from idmap i, person p where
i.handle=p.handle and email=\"$1\""
mysql mydatabase -pmypassword -N -B -e "$QUERY" | while read line ; do
personid=$(echo $line | cut -f1) ; handle=$(echo $line | cut -f2 ) ;
echo $handle ; done ;


Fritz

Re: Tabs missing in batch mode

am 24.04.2006 21:10:44 von Bill Karwin

fritz-bayer@web.de wrote:
> Hi,
>
> in a shell script of mine I'm executing a mysql SELECT in batch mode. I
> want to use the return value for other sql statements.
>
> The problem I'm facing is that the tabs, which seperate the columns
> from each other, are missing in the output.
>
> What am I doing wrong?
>
> #!/bin/sh
> QUERY="select id, i.handle from idmap i, person p where
> i.handle=p.handle and email=\"$1\""
> mysql mydatabase -pmypassword -N -B -e "$QUERY" | while read line ; do
> personid=$(echo $line | cut -f1) ; handle=$(echo $line | cut -f2 ) ;
> echo $handle ; done ;

Try echo "$line" instead of echo $line. The whitespace is being
interpreted by the shell. The shell interprets any amount of whitespace
as equivalent to one space, unless you protect it with quoting.

For example, try the following, typing a tab character where I indicate
"\t" below:

$ echo one \t two \t three

Now try it with quotes:

$ echo "one \t two \t three"

Regards,
Bill K.

Re: Tabs missing in batch mode

am 25.04.2006 09:33:28 von fritz-bayer

Thanks a lot, that caused the problem.