From jau@cs78135006.pp.htv.fi  Sat Mar  8 14:36:11 2003
Return-Path: <jau@cs78135006.pp.htv.fi>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id B6E1C37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  8 Mar 2003 14:36:11 -0800 (PST)
Received: from cs78135006.pp.htv.fi (cs78135006.pp.htv.fi [62.78.135.6])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6A78143F93
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  8 Mar 2003 14:36:10 -0800 (PST)
	(envelope-from jau@cs78135006.pp.htv.fi)
Received: (from jau@localhost)
	by cs78135006.pp.htv.fi (8.9.3/8.9.3/JAU-2.2) id AAA66784;
	Sun, 9 Mar 2003 00:36:07 +0200 (EET)
Message-Id: <200303082236.AAA66784@cs78135006.pp.htv.fi>
Date: Sun, 9 Mar 2003 00:36:07 +0200 (EET)
From: "Jukka A. Ukkonen" <jau@cs78135006.pp.htv.fi>
Reply-To: jau@iki.fi
To: FreeBSD-gnats-submit@freebsd.org
Subject: sh does not undefine a function when unset is issued
X-Send-Pr-Version: 3.2

>Number:         49038
>Category:       bin
>Synopsis:       /bin/sh does not undefine a function when unset is issued
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 08 14:40:07 PST 2003
>Closed-Date:    Mon Mar 10 15:50:05 PST 2003
>Last-Modified:  Mon Mar 10 15:50:05 PST 2003
>Originator:     Jukka A. Ukkonen
>Release:        Multiple - all that I have had a chance to try this on
>Organization:
Private person
>Environment:

	FreeBSD Bourne shell

>Description:

	The bourne shell does not undefine a previously declared shell
	function when unset command is given though the manual pages
	so imply.
	This is a serious portability problem for imported shell scripts.
	Just figure how will a script behave, if there is a function
	called exit which invokes another function which in turn tries
	first "unset exit", does its own work and now tries to invoke
	the real exit...

	Exit()
	{
		unset exit

		Logger -stderr "$*"

		exit 0
	}

	exit()
	{
		...
		Exit "EXIT:" "$*"
	}


>How-To-Repeat:

	sticky()
	{
		echo "STICKY STILL HERE"
		echo "$*"
	}

	unset sticky

	sticky peekaboo
	STICKY STILL HERE
	peekaboo

	The last two lines are the output from the echo.

>Fix:
	
	This is probably simple oversight in forgetting to clean the unset
	name in the function symbol table though the variable name gets
	gets cleared out of the variable symbol table.

>Release-Note:
>Audit-Trail:

From: Robert Drehmel <robert@zoot.drehmel.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc: jau@iki.fi
Subject: Re: bin/49038: /bin/sh does not undefine a function when unset is issued
Date: Sun, 9 Mar 2003 00:49:45 +0100

 Hello.
 
 > The bourne shell does not undefine a previously declared shell
 > function when unset command is given though the manual pages
 > so imply.
 
 I think it is pretty clear that a plain "unset name" does not
 undefine functions.
 
 From the sh(1) manual page:
 
 """
 unset [-fv] name ...
 The specified variables or functions are unset and unexported.
 If the -v option is specified or no options are given, the name
 arguments are treated as variable names.  If the -f option is
 specified, the name arguments are treated as function names.
 """
 
 > This is a serious portability problem for imported shell scripts.
 
 If these shell scripts rely on "unset name" to remove a function
 named "name", they should be regarded as unportable.
 
 From POSIX.1-2001:
 
 """
 If neither -f nor -v is specified, name refers to a variable; if a
 variable by that name does not exist, it is unspecified whether a
 function by that name, if any, shall be unset.
 """
 
 ciao,
 -robert
State-Changed-From-To: open->feedback 
State-Changed-By: robert 
State-Changed-When: Sat Mar 8 18:38:55 PST 2003 
State-Changed-Why:  
Waiting on response from originator. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=49038 
State-Changed-From-To: feedback->closed 
State-Changed-By: robert 
State-Changed-When: Mon Mar 10 15:40:44 PST 2003 
State-Changed-Why:  
The bourne shell in both 4.7-RELEASE and -CURRENT distinguishes 
between variables and functions in its `unset' command. 
To unset functions, the `-f' flag must be explicitly given. 
The problem lay in the documentation of earlier FreeBSD versions. 
Originator considers PR resolved. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=49038 
>Unformatted:
