[gnu.bash.bug] bahs 1.04 core dumps reading a script file

andrewt@watsnew.waterloo.edu (Andrew Thomas) (12/02/89)

Running bash 1.04 on a uVaxII, Ultrix 2.0

I have a shell file which is read when I log in to set my functions.
This one causes a core dump;

------------------------
function distr ()
{
  local machines='watnext watsnew watsup watever watif watsleft'
  local current=`/bin/hostname`
  local curdir=$PWD
  if [ "$1" = "-m" ] ; then
    shift
    machines="$1"
    shift
  done							<-- should be fi
  if [ -z "$1" ] ; then
    echo "Usage: distr [-m machine] <file> [file...]"
    return
  fi
  for file in $* ; do
    if [ ! -f "$file" ] ; then
      echo Distr: $file: not a plain file.
    else
      for i in $machines ; do
        if [ "$i" != "$current" ] ; then
          echo cp -p $file /nfs/${i}${curdir}/$file
          cp -p $file /nfs/${i}${curdir}/$file
        fi
      done
    fi
  done
}
-----------------------------------------

I marked the error in the script, 'done' instead of 'fi'.  It should
still not produce a crash.  The output from bash is:

watsnew.2.102> bash -norc
bash$ . ./tshell
syntax error near `done'
./tshell:10: `  done'
Usage: distr [-m machine] <file> [file...]
can only `return' from a function
syntax error near `}'
./tshell:27: `}'
watsnew.2.103> 

--

Andrew Thomas
andrewt@watsnew.waterloo.edu	Systems Design Eng.	University of Waterloo
"If a million people do a stupid thing, it's still a stupid thing." - Opus

chet@cwns1.CWRU.EDU (Chet Ramey) (12/07/89)

Andrew Thomas reports:

	I have a shell file which is read when I log in to set my functions.
	This one causes a core dump;

	function distr ()
	{
	  local machines='watnext watsnew watsup watever watif watsleft'
	  local current=`/bin/hostname`
	  local curdir=$PWD
	  if [ "$1" = "-m" ] ; then
	    shift
	    machines="$1"
	    shift
	  done						<-- should be fi

I have sent a fix for this to Brian.

Chet Ramey
-- 
Chet Ramey
Network Services Group				"Where's my froggie?"
Case Western Reserve University
chet@ins.CWRU.Edu