[comp.unix.questions] Bourne shell syntax problem?

croten@ltpsun.gsfc.nasa.gov (Charles D. Roten) (04/19/91)

    I am having trouble getting a Bourne shell to run, and have come to
suspect that the problem is in the section where I parse the variables.
The script is rather long (~260 lines) so I will only include the suspect
portion.

-------------------- script follows --------------------
#!/bin/sh

 [comments deleted]

sourcepath=/tmp/zmcdr/tmp
mailhost=charney.gsfc.nasa.gov
tmpdir=/tmp/zmcdr
mailback=0
interactive=0
verbose=0
built=0
dataset=0
normset=0
database=0
localdata=fort.10
localnormal=fort.15
data=""
normal=""
maildest=""

 [stuff that already works deleted]
 
# Switch on the verbosity.

set -x

# Go to the 'working' directory
cd $tmpdir

# Now, parse the rest of the arguments, for cases where there are 1 or more
#    arguments.

for i in $*; do
   case $i in
      -b)   rm temp
            echo '/c     idbase = 1' > temp
            echo 's/c/ /' >> temp
            sed -f temp $sourcepath/beat.f > newbeat.f
            mv newbeat.f beat.f
            database=1
            built=1;;
      -m)   mailback=1;;
      -d)   shift
            datastring=$i
            dataset=1;;
      -n)   shift
            normstring=$i
            normset=1;;
      -v)   verbose=1;;
      -i)   interactive=1;;
      *)    if test "$data" = ""; then
               data=$i
            elif test "$normal = ""; then
               normal=$i
            elif test "$maildest" = ""; then
               maildest=$i
            else break
            fi
   esac
done

 [stuff never reached deleted]
-------------------- end of script --------------------

    Here are the symptoms.

-------------------- begin session log --------------------
$ jobshell zcpjd.m60.tok.data zcpjd.m60.toka.data
+ cd /tmp/zmcdr
./jobshell: syntax error at line 269: `end of file' unexpected
$ wc -l jobshell
     268 jobshell
-------------------- end session log --------------------

    The first command in the section I quoted after 'set -x' executes.
Nothing else does.  I think I hosed the syntax in the section I quoted.
I am fairly sure it *is* a programming error and not just a bug in this
particular port of the Bourne shell because I ran versions of this script
on both a Sun and a Cray with the same results.  BTW, my login shells 
on both machines are /bin/csh, but I was in /bin/sh when testing.

    I would greatly appreciate an explanation of the the nature of the 
goof.  Thanks in advance.

-- 
Charles Roten | STX, Incorporated
Internet: croten@ltpsun.gsfc.nasa.gov [best] *OR* zmcdr@charney.gsfc.nasa.gov
smail:    9701 L Philadelphia Court, Lanham, MD 20706
phone:    (301) 306-1006 (work) ; (301) 317-0872 (home)

urban@cbnewsl.att.com (john.urban) (04/19/91)

In article <4973@dftsrv.gsfc.nasa.gov> croten@ltpsun.gsfc.nasa.gov (Charles D. Roten) writes:
>
>    I am having trouble getting a Bourne shell to run, and have come to
>suspect that the problem is in the section where I parse the variables.
>The script is rather long (~260 lines) so I will only include the suspect
>portion.
>

You're missing the closing " for the test "$normal

>-------------------- script follows --------------------
>#!/bin/sh
>
> [comments deleted]
>
>      *)    if test "$data" = ""; then
>               data=$i
>            elif test "$normal = ""; then

			     ^^^^  missing closing " around normal.

>               normal=$i
>            elif test "$maildest" = ""; then
>               maildest=$i
>            else break
>            fi
>   esac
>done

Sincerely,

John Ben Urban

barb@library.calpoly.edu (Barbara Nash) (04/20/91)

croten@ltpsun.gsfc.nasa.gov (Charles D. Roten) says.......
>
>    I am having trouble getting a Bourne shell to run, and have come to
>suspect that the problem is in the section where I parse the variables.
>The script is rather long (~260 lines) so I will only include the suspect
>portion.
>
>-------------------- script follows --------------------
>#!/bin/sh
>
> [comments deleted]
>
[lotsa stuff deleted for brevity]
>
> [stuff that already works deleted]
> 
># Switch on the verbosity.
>
>set -x
>
># Go to the 'working' directory
>cd $tmpdir
>
># Now, parse the rest of the arguments, for cases where there are 1 or more
>#    arguments.
>
>for i in $*; do
>   case $i in
[lotsa case stuff deleted for brevity]
>      *)    if test "$data" = ""; then
>               data=$i
>            elif test "$normal = ""; then
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
             You've only got three " marks here, you need another after
             "$normal.  This is prolly why you're getting an unexpected
>
>    I would greatly appreciate an explanation of the the nature of the 
>goof.  Thanks in advance.
>

Sure, no problem.  Forgetting a quote seems to be my favorite shell proggin'
error as well.  =-)

Good luck,
Barb


-- 
--------------------------------------------------------------------------------
Barbara Nash, Asst. SysAdmin                       barb@library.calpoly.edu
Kennedy Library Computer Services                  bnash@polyslo.calpoly.edu
Disclaimer:  My opinions are my own, the library has enough without taking mine.

barb@library.calpoly.edu (Barbara Nash) (04/20/91)

croten@ltpsun.gsfc.nasa.gov (Charles D. Roten) says.......
>
>    I am having trouble getting a Bourne shell to run, and have come to
>suspect that the problem is in the section where I parse the variables.
>The script is rather long (~260 lines) so I will only include the suspect
>portion.
>
>-------------------- script follows --------------------
>#!/bin/sh
>
> [comments deleted]
>
[lotsa stuff deleted for brevity's sake]
>
># Now, parse the rest of the arguments, for cases where there are 1 or more
>#    arguments.
>
>for i in $*; do
>   case $i in
[lotsa case stuff deleted for more brevity]
>      *)    if test "$data" = ""; then
>               data=$i
>            elif test "$normal = ""; then
                       ^^^^^^^^^^^^^
                       You've only got three quotes here, you need another
                       after the "$normal.  This is prolly why you are getting
                       the unexpected EOF error.
>
>    I would greatly appreciate an explanation of the the nature of the 
>goof.  Thanks in advance.

Sure, no problem.  Forgetting a quote mark seems to be my favorite shell
proggin' error as well!  =-) =-)


Good luck,
Barb



-- 
--------------------------------------------------------------------------------
Barbara Nash, Asst. SysAdmin                       barb@library.calpoly.edu
Kennedy Library Computer Services                  bnash@polyslo.calpoly.edu
Disclaimer:  My opinions are my own, the library has enough without taking mine.

barb@library.calpoly.edu (Barbara Nash) (04/20/91)

Sorry about my double posting there...my machine hiccupped on the first,
and I didn't know if it went through...

Barb


-- 
--------------------------------------------------------------------------------
Barbara Nash, Asst. SysAdmin                       barb@library.calpoly.edu
Kennedy Library Computer Services                  bnash@polyslo.calpoly.edu
Disclaimer:  My opinions are my own, the library has enough without taking mine.

jeff@onion.rain.com (Jeff Beadles) (04/21/91)

In croten@ltpsun.gsfc.nasa.gov (Charles D. Roten) writes:

>    I am having trouble getting a Bourne shell to run, and have come to
>suspect that the problem is in the section where I parse the variables.
>The script is rather long (~260 lines) so I will only include the suspect
>portion.
>
...
>      *)    if test "$data" = ""; then
>               data=$i
>            elif test "$normal = ""; then
                              ^^^

The problem is that you are missing a quote.  This is probably one of the
harder-to-find bugs with a shell script.



Have fun!
	-Jeff


-- 
Jeff Beadles		jeff@onion.rain.com