0

Below Unix shell script fails saying unexpected end of file at the mysql line before $selectg line. Not sure what mistake i am doing. Provided part of script below. Could anyone help me out.

    #!/bin/bash
  ip="77.299.113.81" 
  pass="-ptest123"

        read -d '' selectg <<EOGG   SELECT * FROM agstatus ; EOGG

        for row in `mysql  -h $ip -u root $pass "ruttt" -e "SELECT  databasename FROM master.customers"`; do
           rownum=$((rownum+1))
           echo "Row:$row"
        if [ $rownum -ne 1 ]; then
        mysql -u tsadm -p'test123' -h 77.299.113.81 Csfgat  << eof
        $selectg
        eof
        fi
        done
        echo "done"

1 Answer 1

1

The end token of a here document has to be on a line by itself:

read -d '' selectg <<EOGG
SELECT * FROM agstatus;
EOGG

Alternatively, you can use a here string:

read -d '' selectg <<< "SELECT * FROM agstatus;"

Or in your specific case, a plain ol' assignment:

selectg="SELECT * FROM agstatus;"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for your time and info. Problem was I had Tab after EOF. Deleted the tab and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.