1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
# export-p.tst: test of the export built-in for any POSIX-compliant shell
posix="true"
test_oE -e 0 'exporting one variable' -e
export a=bar
echo 1 $a
sh -c 'echo 2 $a'
__IN__
1 bar
2 bar
__OUT__
test_oE -e 0 'exporting many variables' -e
a=X b=B c=X
export a=A b c=C
echo 1 $a $b $c
sh -c 'echo 2 $a $b $c'
__IN__
1 A B C
2 A B C
__OUT__
test_oE -e 0 'separator preceding operand' -e
export -- a=foo
echo 1 $a
sh -c 'echo 2 $a'
__IN__
1 foo
2 foo
__OUT__
test_oE -e 0 'reusing printed exported variables'
export a=A
e="$(export -p)"
unset a
a=X
eval "$e"
sh -c 'echo $a'
__IN__
A
__OUT__
test_oE 'exporting with assignments'
a=A export b=B
# POSIX requires $a to persist after the export built-in,
# but it is unspecified whether $a is exported.
echo $a
# $a does not affect $b being exported.
sh -c 'echo $b'
__IN__
A
B
__OUT__
test_O -d -e n 'read-only variable cannot be re-assigned'
readonly a=1
export a=2
# The export built-in fails because of the readonly variable.
# Since it is a special built-in, the non-interactive shell exits.
echo not reached
__IN__
# vim: set ft=sh ts=8 sts=4 sw=4 et:
|