Subject: /bin/sh and functions
To: None <tech-userlevel@NetBSD.org>
From: Klaus Heinz <k.heinz.mai.vier@onlinehome.de>
List: tech-userlevel
Date: 05/25/2004 16:39:24
--MGYHOYXEY6WxJCY8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Hi,

on a fresh install of NetBSD/amiga 2.0_BETA:

  $ echo $SHELL
  /bin/sh
  $ type pgrep
  pgrep is a shell function
  $ unset pgrep
  $ type pgrep
  pgrep is a shell function
  $ pgrep
  Usage: grep [OPTION]... PATTERN [FILE]...
  Try `grep --help' for more information.

According to the man page sh(1)

	unset name ...
            The specified variables and functions are unset and unexported.
            If a given name corresponds to both a variable and a function,
            both the variable and the function are unset.

this does not work as advertised. The last sentence is completely wrong.

A look at the source code and some experiments show that 'unset' knows
options e, v and f and acts on f and v as known from ksh and bash.
Option 'e' seems to be a substitute for 'typeset +x' in ksh.

Is the appended patch acceptable?


ciao
     Klaus


--MGYHOYXEY6WxJCY8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="sh.1.diff"

--- sh.1.orig	Sun Dec 21 12:16:23 2003
+++ sh.1	Tue May 25 16:38:00 2004
@@ -1243,7 +1243,8 @@
 .It export Fl p
 The specified names are exported so that they will appear in the
 environment of subsequent commands.
-The only way to un-export a variable is to unset it.
+The only way to un-export a variable is to unset it with option
+.Fl e.
 The shell allows the value of a variable to be set at the
 same time it is exported by writing
 .Pp
@@ -1761,10 +1762,19 @@
 If
 .Fl a
 is specified, all aliases are removed.
-.It unset Ar name ...
-The specified variables and functions are unset and unexported.
-If a given name corresponds to both a variable and a function, both
-the variable and the function are unset.
+.It unset Xo
+.Op Fl efv
+.Op Ar name ...
+.Xc
+The specified variables (
+.Fl v ,
+the default) and functions (
+.Fl f
+) are unset. Option
+.Fl e
+is only valid for variables and un-exports them.
+The exit status reflects whether the variables or function were already unset
+(non-zero) or not (zero).
 .It wait Op Ar job
 Wait for the specified job to complete and return the exit status of the
 last process in the job.

--MGYHOYXEY6WxJCY8--