diff options
author | jilles <jilles@FreeBSD.org> | 2012-07-15 10:19:43 +0000 |
---|---|---|
committer | jilles <jilles@FreeBSD.org> | 2012-07-15 10:19:43 +0000 |
commit | 689774f8e79cc120c6606a52baf8a4a0a17ed6b6 (patch) | |
tree | 2e7b1c68d295b04b7db1b3b87ea0c5a9c84a9291 /tools/regression | |
parent | 057a8ab456da82a3e40e6fba4629ba852dd79255 (diff) | |
download | FreeBSD-src-689774f8e79cc120c6606a52baf8a4a0a17ed6b6.zip FreeBSD-src-689774f8e79cc120c6606a52baf8a4a0a17ed6b6.tar.gz |
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.
PR: bin/166771
Diffstat (limited to 'tools/regression')
-rw-r--r-- | tools/regression/bin/sh/expansion/export2.0 | 24 | ||||
-rw-r--r-- | tools/regression/bin/sh/expansion/export3.0 | 30 | ||||
-rw-r--r-- | tools/regression/bin/sh/expansion/local1.0 | 28 | ||||
-rw-r--r-- | tools/regression/bin/sh/expansion/local2.0 | 34 | ||||
-rw-r--r-- | tools/regression/bin/sh/expansion/readonly1.0 | 7 |
5 files changed, 123 insertions, 0 deletions
diff --git a/tools/regression/bin/sh/expansion/export2.0 b/tools/regression/bin/sh/expansion/export2.0 new file mode 100644 index 0000000..57f64e7 --- /dev/null +++ b/tools/regression/bin/sh/expansion/export2.0 @@ -0,0 +1,24 @@ +# $FreeBSD$ + +w='@ @' +check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" +} + +export v=$w +check + +HOME=/known/value +check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" +} + +export v=~ +check + +check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" +} + +export v=x:~ +check diff --git a/tools/regression/bin/sh/expansion/export3.0 b/tools/regression/bin/sh/expansion/export3.0 new file mode 100644 index 0000000..a1a0e66 --- /dev/null +++ b/tools/regression/bin/sh/expansion/export3.0 @@ -0,0 +1,30 @@ +# $FreeBSD$ + +w='@ @' +check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" +} + +command export v=$w +check +command command export v=$w +check + +HOME=/known/value +check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" +} + +command export v=~ +check +command command export v=~ +check + +check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" +} + +command export v=x:~ +check +command command export v=x:~ +check diff --git a/tools/regression/bin/sh/expansion/local1.0 b/tools/regression/bin/sh/expansion/local1.0 new file mode 100644 index 0000000..3477835 --- /dev/null +++ b/tools/regression/bin/sh/expansion/local1.0 @@ -0,0 +1,28 @@ +# $FreeBSD$ + +run_test() { + w='@ @' + check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" + } + + local v=$w + check + + HOME=/known/value + check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" + } + + local v=~ + check + + check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" + } + + local v=x:~ + check +} + +run_test diff --git a/tools/regression/bin/sh/expansion/local2.0 b/tools/regression/bin/sh/expansion/local2.0 new file mode 100644 index 0000000..1984290 --- /dev/null +++ b/tools/regression/bin/sh/expansion/local2.0 @@ -0,0 +1,34 @@ +# $FreeBSD$ + +run_test() { + w='@ @' + check() { + [ "$v" = "$w" ] || echo "Expected $w got $v" + } + + command local v=$w + check + command command local v=$w + check + + HOME=/known/value + check() { + [ "$v" = ~ ] || echo "Expected $HOME got $v" + } + + command local v=~ + check + command command local v=~ + check + + check() { + [ "$v" = "x:$HOME" ] || echo "Expected x:$HOME got $v" + } + + command local v=x:~ + check + command command local v=x:~ + check +} + +run_test diff --git a/tools/regression/bin/sh/expansion/readonly1.0 b/tools/regression/bin/sh/expansion/readonly1.0 new file mode 100644 index 0000000..5ad0e14 --- /dev/null +++ b/tools/regression/bin/sh/expansion/readonly1.0 @@ -0,0 +1,7 @@ +# $FreeBSD$ + +w='@ @' + +v=0 HOME=/known/value +readonly v=~:~/:$w +[ "$v" = "$HOME:$HOME/:$w" ] || echo "Expected $HOME/:$w got $v" |