]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/commit
MFC r238468: sh: Expand assignment-like words specially for
authorjilles <jilles@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Sun, 13 Apr 2014 21:49:44 +0000 (21:49 +0000)
committerjilles <jilles@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Sun, 13 Apr 2014 21:49:44 +0000 (21:49 +0000)
commit6814cce74d7c2477aeb4c94b5a1ef88c242486d1
tree93e3756db270e0d68b173df57373ad7129dc66d0
parent4ef8f205807982c31b0f1270cc68b3f145303fc6
MFC r238468: sh: Expand assignment-like words specially for
export/readonly/local.

Examples:
  export x=~
now expands the tilde
  local y=$1
is now safe, even if $1 contains IFS characters or metacharacters.

For a word to "look like an assignment", it must start with a name followed
by an equals sign, none of which may be quoted.

The special treatment applies when the first word (potentially after
"command") is "export", "readonly" or "local". There may be quoting
characters but no expansions. If "local" is overridden with a function there
is no special treatment ("export" and "readonly" cannot be overridden with a
function).

If things like
  local arr=(1 2 3)
are ever allowed in the future, they cannot call a "local" function. This
would either be a run-time error or it would call the builtin.

This matches Austin Group bug #351, planned for the next issue of POSIX.1.

As for the MFC, it is easy to depend on this feature inadvertently, and
adding this fixes a regression from stable/8 that may be apparent in things
like
  local x=${y+a @}.

PR: bin/166771
Relnotes: yes

git-svn-id: svn://svn.freebsd.org/base/stable/9@264423 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
bin/sh/eval.c
bin/sh/exec.c
bin/sh/exec.h
bin/sh/sh.1
tools/regression/bin/sh/expansion/export2.0 [new file with mode: 0644]
tools/regression/bin/sh/expansion/export3.0 [new file with mode: 0644]
tools/regression/bin/sh/expansion/local1.0 [new file with mode: 0644]
tools/regression/bin/sh/expansion/local2.0 [new file with mode: 0644]
tools/regression/bin/sh/expansion/readonly1.0 [new file with mode: 0644]