Re: shell script again!
Posted in 1999
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.
You values statement should include quotes around any character or date
values. Something like:
INSERT INTO mytable
VALUES("$name","$birth","$addr")
I don't know about the '==' syntax, but then I'm a Bourne again shell
programmer myself. :-) I would use:
read answer
if [ "X$answer" = "XY" -o "X$answer" = "Xy" ]
then .....
Hope that helps,
--
Mark.
+----------------------------------------------------------+-----------+
|Mark D. Stock - Informix SA http://www.informix.com |//////// /|
|mailto:mdstock@informix.com http://www.informix.com/idn |///// / //|
|http://www.iiug.org +-----------------------------------+//// / ///|
| Tel: +27 11 807 0313 |What year 2000 bug? year 2000 bug? |/// / ////|
| Fax: +27 838250 2325 |year 2000 bug? year 2000 bug? year |// / /////|
|Cell: +27 83 250 2325 |2000 bug? year 2000 bug? year 1900 |/ ////////|
+----------------------+-----------------------------------+-----------+