Module Name:    src
Committed By:   kre
Date:           Fri Sep 18 06:48:28 UTC 2020

Modified Files:
        src/bin/sh: sh.1

Log Message:
Correct an incorrectly quoted (unquoted, but should be) example used in
the "local" built-in command description (pointed out by mrg@ via uwe@ in
private e-mail).

Add a description to the export command of why this quoting is required,
and then refer to it from local and readonly (explained in export as that
one comes first).

Note that some shells parse export/local/readonly (and often more) as
"declarative" commands, and this quoting isn't needed (provided the
command name is literal and not the result of an expansion) making
X=$Y type args not require quoting, as they often don't in a regular
variable assignment (preceding, or not part of, another command).
POSIX is going to allow, but not require, that behaviour.  We do not
implement it.


To generate a diff of this commit:
cvs rdiff -u -r1.227 -r1.228 src/bin/sh/sh.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/bin/sh/sh.1
diff -u src/bin/sh/sh.1:1.227 src/bin/sh/sh.1:1.228
--- src/bin/sh/sh.1:1.227	Tue Aug 25 19:42:02 2020
+++ src/bin/sh/sh.1	Fri Sep 18 06:48:28 2020
@@ -1,4 +1,4 @@
-.\"	$NetBSD: sh.1,v 1.227 2020/08/25 19:42:02 kre Exp $
+.\"	$NetBSD: sh.1,v 1.228 2020/09/18 06:48:28 kre Exp $
 .\" Copyright (c) 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
 .\"
@@ -31,7 +31,7 @@
 .\"
 .\"	@(#)sh.1	8.6 (Berkeley) 5/4/95
 .\"
-.Dd August 20, 2020
+.Dd September 18, 2020
 .Dt SH 1
 .\" everything except c o and s (keep them ordered)
 .ds flags abCEeFfhIiLmnpquVvXx
@@ -2591,6 +2591,35 @@ same time it is exported (or unexported,
 .Pp
 .Dl export [-nx] name=value
 .Pp
+Note that in such a usage, the
+.Dq name=value
+argument often needs to be quoted,
+more often than is required of an assignment statement,
+as, like with any other command, the command name and
+arguments are all subject to the various expansions,
+including filename expansion and field splitting,
+before the
+.Ic export
+command is invoked.
+With the default value for
+.Dv IFS :
+.Bd -unfilled -compact -offset indent
+X='a b c'
+export Y=$X
+.Ed
+the command invoked would be
+.Dl "export Y=a b c"
+exporting
+.Dv Y ,
+with the value
+.Dq a
+and also exporting the variables named
+.Dq b
+and
+.Dq c ,
+which is probably not as intended.
+.Ed
+.Pp
 With no arguments the export command lists the names of all
 set exported variables,
 or if
@@ -3060,12 +3089,15 @@ Note that any variable references on the
 been expanded before
 .Ic local
 is executed, so expressions like
-.Pp
-.Dl "local -N X=${X}"
+.Bd -unfilled -offset indent
+local -N X="${X}"
+.Ed
 .Pp
 are well defined, first $X is expanded, and then the command run is
-.Pp
-.Dl "local -N X=old-value-of-X"
+.Dl "local -N X='old-value-of-X'"
+See the description of the
+.Ic export
+built-in command for notes on why quoting the value is required.
 .Pp
 After arranging to preserve the old value and attributes, of
 .Dv X
@@ -3269,6 +3301,10 @@ to be set at the same time it is marked 
 .Pp
 .Dl readonly name=value
 .Pp
+where the value often needs to be quoted, as explained for the
+.Ic export
+command.
+.Pp
 With no arguments the
 .Ic readonly
 command lists the names of all set read only variables.

Reply via email to