mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-03-09 15:50:02 +00:00
Export all variables assigned to while allexport is on (#431)
All variables that are assigned a value should be exported while
the allexport shell option is enabled. This works in most cases,
but variables assigned to with ${var:=foo} or $((var=123)) aren't
exported while allexport is on.
src/cmd/ksh93/sh/name.c:
- nv_putval(): This is the central assignment function; all forms
of variable assignment end up here. So this is the best place
to check for SH_ALLEXPORT and turn on the export attribute.
- nv_setlist(): Remove allexport handling, now redundant.
src/cmd/ksh93/bltins/read.c: sh_readline():
- Remove allexport handling, now redundant.
src/cmd/ksh93/sh/main.c: sh_main():
- nv_putval() is used to initialize PS4 and IFS using nv_putval();
this is after an -a/--allexport specified on the ksh command
line has been processed, so temporarily turn that off.
Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
parent
0863a8eb29
commit
8e72608c1c
9 changed files with 85 additions and 17 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# #
|
||||
# This software is part of the ast package #
|
||||
# Copyright (c) 1982-2012 AT&T Intellectual Property #
|
||||
# Copyright (c) 2020-2021 Contributors to ksh 93u+m #
|
||||
# Copyright (c) 2020-2022 Contributors to ksh 93u+m #
|
||||
# and is licensed under the #
|
||||
# Eclipse Public License, Version 1.0 #
|
||||
# by AT&T Intellectual Property #
|
||||
|
|
@ -705,5 +705,30 @@ do
|
|||
(( ${var:=1} == 0 )) || err_exit "\${var:=1} should yield 0 after typeset -$flag var=0 (got '$var')"
|
||||
done
|
||||
|
||||
# ======
|
||||
# allexport tests
|
||||
# https://github.com/ksh93/ksh/pull/431
|
||||
set -o allexport
|
||||
unset bar
|
||||
: ${bar:=baz}
|
||||
exp='typeset -x bar=baz'
|
||||
got=$(typeset -p bar)
|
||||
[[ $got == "$exp" ]] || err_exit 'Variable ${bar} should be exported' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
# Set variable in arithmetic expressions
|
||||
unset bar
|
||||
((bar=1))
|
||||
exp='typeset -x bar=1'
|
||||
got=$(typeset -p bar)
|
||||
[[ $got == "$exp" ]] || err_exit 'Variable ${bar} should be exported' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
unset bar
|
||||
: $((bar=2))
|
||||
exp='typeset -x bar=2'
|
||||
got=$(typeset -p bar)
|
||||
[[ $got == "$exp" ]] || err_exit 'Variable ${bar} should be exported' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
set +o allexport
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# #
|
||||
# This software is part of the ast package #
|
||||
# Copyright (c) 1982-2012 AT&T Intellectual Property #
|
||||
# Copyright (c) 2020-2021 Contributors to ksh 93u+m #
|
||||
# Copyright (c) 2020-2022 Contributors to ksh 93u+m #
|
||||
# and is licensed under the #
|
||||
# Eclipse Public License, Version 1.0 #
|
||||
# by AT&T Intellectual Property #
|
||||
|
|
@ -98,4 +98,37 @@ false
|
|||
false
|
||||
[[ $(.x.runxrun) == 'xfun local bar' ]] || err_exit 'namespace function on FPATH failed'
|
||||
|
||||
# ======
|
||||
# Namespace variables should retain their exoprt attribute, even
|
||||
# though they are not actually exported outside the namespace block.
|
||||
set -o allexport
|
||||
namespace foo_nam
|
||||
{
|
||||
typeset bar
|
||||
typeset foo
|
||||
typeset baz=baz
|
||||
integer three
|
||||
}
|
||||
: ${.foo_nam.bar:=BAZ}
|
||||
exp='typeset -x .foo_nam.bar=BAZ'
|
||||
got=$(typeset -p .foo_nam.bar)
|
||||
[[ $got == "$exp" ]] || err_exit 'Variable ${.foo_nam.bar} did not retain -x attribute' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
.foo_nam.foo=FOO
|
||||
exp='typeset -x .foo_nam.foo=FOO'
|
||||
got=$(typeset -p .foo_nam.foo)
|
||||
[[ $got == "$exp" ]] || err_exit 'Variable ${.foo_nam.foo} did not retain -x attribute' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
exp='typeset -x .foo_nam.baz=baz'
|
||||
got=$(typeset -p .foo_nam.baz)
|
||||
[[ $got == "$exp" ]] || err_exit 'Variable ${.foo_nam.baz} did not retain -x attribute' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
((.foo_nam.three=3))
|
||||
exp='typeset -x -l -i .foo_nam.three=3'
|
||||
got=$(typeset -p .foo_nam.three)
|
||||
[[ $got == "$exp" ]] || err_exit 'Variable ${.foo_nam.three} did not retain -x attribute' \
|
||||
"(expected $(printf %q "$exp"), got $(printf %q "$got"))"
|
||||
set +o allexport
|
||||
|
||||
# ======
|
||||
exit $((Errors<125?Errors:125))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue