blob: 94af79060416f21adfb128adda970fb0b13f11b0 [file] [log] [blame]
Denys Vlasenko0eed3552017-07-21 13:37:25 +02001unset a b
2#
3readonly a=A
4b=B
5readonly b
6# readonly on already readonly var is harmless:
7readonly b a
8readonly | grep '^readonly [ab]='
9# this should work:
10export a b
11export -n a b
12echo Ok:$?
13env | grep -e^a= -e^b= # shows nothing
14
15echo
16# these should all fail (despite the same value being assigned)
17# bash does not abort even in non-interactive more (in script)
18# ash does, using subshell to continue
19true; (a=A)
20echo Fail:$?
21true; (readonly a=A)
22echo Fail:$?
23
24echo
25# in bash, assignment in export fails, but export succeeds! :)
26# we don't mimic that!
27true; (export a=Z)
28echo Fail:$?
29#env | grep '^a='
30#echo "^^^a is exported"
31export -n a # undo that bashism, if it happens
32
33## ash: assignment errors in "a=Z CMD" lead to CMD not executed
34## echo
35## export b
36## # this fails to both set and export a:
37## a=Z env | echo grep '^[ab]='
38## echo "^^^a is not exported"
39## # but external command does get executed, and $? is not mangled (stays 42):
40## (exit 42); a=Z env echo Visible:$?
41
42echo
43# ash: this fails *silently*, bug? bash says "cannot unset: readonly variable"
44true; unset a
45echo Fail:$?