blob: 3ace9b767ed5349906a7f286a9c344fa46faa894 [file] [log] [blame]
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +02001unset a b
2
Denys Vlasenko38ef39a2017-07-18 01:40:01 +02003readonly a=A
4b=B
5readonly b
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +02006# readonly on already readonly var is harmless:
Denys Vlasenko38ef39a2017-07-18 01:40:01 +02007readonly b a
8readonly | grep '^readonly [ab]='
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +02009# this should work:
Denys Vlasenko38ef39a2017-07-18 01:40:01 +020010export a b
11export -n a b
12echo Ok:$?
13env | grep -e^a= -e^b= # shows nothing
14
15# these should all fail (despite the same value being assigned)
16# bash does not abort even in non-interactive more (in script)
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020017true; a=A
18echo Fail:$?
19true; readonly a=A
20echo Fail:$?
21
22# in bash, assignment in export fails, but export succeeds! :)
23# we don't mimic that!
24true; export a=Z
Denys Vlasenko38ef39a2017-07-18 01:40:01 +020025echo Fail:$?; true
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020026#env | grep '^a='
27#echo "^^^a is exported"
28export -n a # undo that bashism, if it happens
29
30export b
31# this fails to both set and export a:
32a=Z env | grep '^[ab]=' # command still runs
33echo "^^^a is not exported"
34
Denys Vlasenko38ef39a2017-07-18 01:40:01 +020035unset a
36echo Fail:$?; true