shell script again!
Posted in 1999
Topics: Server Administration
Last week I posted "shell script help" and got help, I appreciate
those who helped me very much.
When I execute this shell script ,it prompts me to type in
name,birth,addr. After that it shows:
________________________________________________
Database selected.
201: A syntax error has occurred.
Error in line 2Near character position 7
Database closed.
continue?
_______________________________________________
How this happen? And no matter what I type after "continue?",it will
continue execute "type in name: type in birth: type in addr:".
The shell script is as below:
<insert.sh>
flag=1
while test $flag==1
do
echo type in name:
read name
echo type in birth:
read birth
echo type in addr:
read addr
dbaccess $1 <<-EOF
INSERT INTO mytable
VALUES($name,$birth,$addr)
EOF
echo continue?
read answer
if test $answer=='y'
then flag=1
else flag=0
fidone
Any help will be gratefully appreciated.
Thanks in advance.
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
carina@371.net wrote:
> Last week I posted "shell script help" and got help, I appreciate
> those who helped me very much.
> When I execute this shell script ,it prompts me to type in
> name,birth,addr. After that it shows:
> ________________________________________________
> Database selected.
>
> 201: A syntax error has occurred.
> Error in line 2> Near character position 7
>
> Database closed.
>
> continue?
> _______________________________________________
>
> How this happen? And no matter what I type after "continue?",it will
> continue execute "type in name: type in birth: type in addr:".
>
> The shell script is as below:
> <insert.sh>
> flag=1
> while test $flag==1
> do
> echo type in name:
> read name
> echo type in birth:
> read birth
> echo type in addr:
> read addr
> dbaccess $1 <<-EOF
> INSERT INTO mytable
> VALUES($name,$birth,$addr)
> EOF
> echo continue?
> read answer
> if test $answer=='y'
> then flag=1
> else flag=0
> fi> done
>
> Any help will be gratefully appreciated.
> Thanks in advance.
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
Hi,
I think the second line should be:
while test $flag == 1
or
while [ $flag == 1 ]
Note the spaces before and after ==
Regards
--
Helmut Leininger
Bull AG / Vienna
Unix Support
Email: h.leininger@bull.at
helmut.leininger@bull.net
This opinion is mine and not necessarily that of my employer.
No guarantees whatsoever.
carina@371.net wrote:
> Last week I posted "shell script help" and got help, I appreciate
> those who helped me very much.
> When I execute this shell script ,it prompts me to type in
> name,birth,addr. After that it shows:
> ________________________________________________
> Database selected.
>
> 201: A syntax error has occurred.
> Error in line 2> Near character position 7
>
> Database closed.
>
> continue?
> _______________________________________________
>
> How this happen? And no matter what I type after "continue?",it will
> continue execute "type in name: type in birth: type in addr:".
>
> The shell script is as below:
> <insert.sh>
> flag=1
> while test $flag==1
> do
> echo type in name:
> read name
> echo type in birth:
> read birth
> echo type in addr:
> read addr
> dbaccess $1 <<-EOF
> INSERT INTO mytable
> VALUES($name,$birth,$addr)
> EOF
> echo continue?
> read answer
> if test $answer=='y'
> then flag=1
> else flag=0
> fi> done
>
> Any help will be gratefully appreciated.
> Thanks in advance.
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
You should put the strings to display by echo within quotes to avoid
that the shell does rubbish.
e.g.
echo continue?
will output "continuex" if there is a file named "x" in the current
directory.
echo "continue?" will give you a "correct" result at any time.
Regards
--
Helmut Leininger
Bull AG / Vienna
Unix Support
Email: h.leininger@bull.at
helmut.leininger@bull.net
This opinion is mine and not necessarily that of my employer.
No guarantees whatsoever.
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hallo,
<p>quote your echoed strings as Helmut Leininger suggests and I would also
quote variables in your insert statement (see below)
<br>to prevent shell doing sth unexpected.
<p>Test command in a new version should also work.
<p>flag=1
<br>while test $flag = 1
<br>do
<br> echo "type in name: "
<br> read name
<br> echo "type in birth: "
<br> read birth
<br> echo "type in addr: "
<br> read addr
<br> dbaccess $1 <<-EOF
<br> INSERT INTO mytab
<br> VALUES("$name","$birth","$addr")
<br> EOF
<br> echo "continue? "
<br> read answer
<br> if test $answer = y
<br> then flag=1
<br> else flag=0
<br> fi
<br>done
<p>Regards
<br>Ch.
<p>carina@371.net wrote:
<blockquote TYPE=CITE>Last week I posted "shell script help" and got help,
I appreciate
<br>those who helped me very much.
<br>When I execute this shell script ,it prompts me to type in
<br>name,birth,addr. After that it shows:
<br>________________________________________________
<br>Database selected.
<p> 201: A syntax error has occurred.
<br>Error in line 2
<br>Near character position 7
<p>Database closed.
<p>continue?
<br>_______________________________________________
<p>How this happen? And no matter what I type after "continue?",it will
<br>continue execute "type in name: type in birth: type in addr:".
<p>The shell script is as below:
<br><insert.sh>
<br>flag=1
<br>while test $flag==1
<br>do
<br> echo type in name:
<br> read name
<br> echo type in birth:
<br> read birth
<br> echo type in addr:
<br> read addr
<br> dbaccess $1 <<-EOF
<br> INSERT INTO mytable
<br> VALUES($name,$birth,$addr)
<br> EOF
<br> echo continue?
<br> read answer
<br> if test $answer=='y'
<br>
then flag=1
<br>
else flag=0
<br> fi
<br>done
<p>Any help will be gratefully appreciated.
<br>Thanks in advance.
<p>Sent via Deja.com <a href="http://www.deja.com/">http://www.deja.com/</a>
<br>Share what you know. Learn what you don't.</blockquote>
</html>
Hi,
I don't know if the newsgroup have recceived my previous message.
To correct this error please, change the following line in your shell
script.
INSERT INTO mytable
VALUES($name,$birth,$addr)
by:
INSERT INTO mytable
VALUES("$name","$birth","$addr");
To test it, just try the two followings statement with dbaccess.
- Wrong statetement:
INSERT INTO mytable VALUES(Jan,12/12/1964,21 bakerstree)
This one give an Error 201.
- Right Statement:
INSERT INTO mytable VALUES("Jan","12/12/1964","21 bakerstree"); This run perfectly
Best Regards,
Jan
<carina@371.net> wrote in message news:7jnatk$6l1$1@nnrp1.deja.com...
> Last week I posted "shell script help" and got help, I appreciate
> those who helped me very much.
> When I execute this shell script ,it prompts me to type in
> name,birth,addr. After that it shows:
> ________________________________________________
> Database selected.
>
>
> 201: A syntax error has occurred.
> Error in line 2> Near character position 7
>
>
> Database closed.
>
> continue?
> _______________________________________________
>
> How this happen? And no matter what I type after "continue?",it will
> continue execute "type in name: type in birth: type in addr:".
>
> The shell script is as below:
> <insert.sh>
> flag=1
> while test $flag==1
> do
> echo type in name:
> read name
> echo type in birth:
> read birth
> echo type in addr:
> read addr
> dbaccess $1 <<-EOF
> INSERT INTO mytable
> VALUES($name,$birth,$addr)
> EOF
> echo continue?
> read answer
> if test $answer=='y'
> then flag=1
> else flag=0
> fi> done
>
> Any help will be gratefully appreciated.
> Thanks in advance.
>
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
carina@371.net wrote:
>
> Last week I posted "shell script help" and got help, I appreciate
> those who helped me very much.
> When I execute this shell script ,it prompts me to type in
> name,birth,addr. After that it shows:
> ________________________________________________
> Database selected.
>
> 201: A syntax error has occurred.
> Error in line 2> Near character position 7
>
> Database closed.
It is complaining about line 2 char 7 which is the open parenthesis
of the VALUES clause. Are you certain it is a left paren and not a
graphics or Euro character that LOOKs like a left paren? Also try
adding the '-e' flag to dbaccess before the database name so that the
query, after var replacement, is echoed. This will make debugging
easier. Another thing to try is to run the script with "sh -x -v" so
you can see the parameter replacement as it happens and the loop
response.
Art S. Kagel