Bug 18447

Summary: /bin/sh: wrong parse eval
Product: Base System Reporter: mori <mori>
Component: binAssignee: Martin Cracauer <cracauer>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 3.4-STABLE   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description mori 2000-05-08 12:40:02 UTC
This problem is on /bin/sh.

If /bin/sh evaluates a string with `eval' statement and the string
has semicolon at the end, then /bin/sh doesn't process the `eval'
statement.

for example:

  $ /bin/sh -c 'eval echo t'
  t
  $ /bin/sh -c 'eval echo t;'
  $

or

  $ cat test.sh
  #! /bin/sh
  cmd1='eval echo 1;'
  cmd2='eval echo 2'
  eval $cmd1
  eval $cmd2
  $ /bin/sh test.sh
  2
  $

And if the string has multiplue eval statement, then /bin/sh doesn't
process first eval statements, but processes others.

for example:

  $ /bin/sh -c 'eval echo 1; eval echo 2; eval echo 3;'
  2
  3
  $

I think its behavior is /bin/sh's bug.  Other shells reading Bourne
shell script, such as bash or SunOS's /bin/sh, process all eval
statement for above cases.  But NetBSD's /bin/sh is same as FreeBSD.

Fix: To fix, apply this patch to src/bin/sh/parser.c
How-To-Repeat: 
Simple example is

 $ /bin/sh -c 'eval echo 1; eval echo 2;'

The result is

 2

but we expected 

 1
 2
Comment 1 Sheldon Hearn freebsd_committer freebsd_triage 2000-05-08 15:41:50 UTC
Responsible Changed
From-To: freebsd-bugs->cracauer

I'm sure this is a duplicate of another PR, but I can't find the 
imaginary "other PR", so I'm just assigning this to our shell's  
maintainer. 
Comment 2 Martin Cracauer freebsd_committer freebsd_triage 2000-05-15 14:02:49 UTC
State Changed
From-To: open->closed

Suggested fix applied to -current.  Thanks! 
Will be in 4-stable before 4.1.