Tabs missing in batch mode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • fritz-bayer@web.de

    #1

    Tabs missing in batch mode

    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.hand le 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

  • Bill Karwin

    #2
    Re: Tabs missing in batch mode

    fritz-bayer@web.de wrote:[color=blue]
    > 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.hand le 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 ;[/color]

    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.

    Comment

    • fritz-bayer@web.de

      #3
      Re: Tabs missing in batch mode

      Thanks a lot, that caused the problem.

      Comment

      Working...