blob: 0833ccf298940f9bb7404918cc68616bf4b775f8 [file] [log] [blame]
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +02001unset a b
Denys Vlasenkof645e152017-07-18 03:23:07 +02002#
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
Denys Vlasenkof645e152017-07-18 03:23:07 +020015echo
Denys Vlasenko38ef39a2017-07-18 01:40:01 +020016# these should all fail (despite the same value being assigned)
17# bash does not abort even in non-interactive more (in script)
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020018true; a=A
19echo Fail:$?
20true; readonly a=A
21echo Fail:$?
22
Denys Vlasenkof645e152017-07-18 03:23:07 +020023echo
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020024# in bash, assignment in export fails, but export succeeds! :)
25# we don't mimic that!
26true; export a=Z
Denys Vlasenkof645e152017-07-18 03:23:07 +020027echo Fail:$?
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020028#env | grep '^a='
29#echo "^^^a is exported"
30export -n a # undo that bashism, if it happens
31
Denys Vlasenkof645e152017-07-18 03:23:07 +020032echo
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020033export b
34# this fails to both set and export a:
Denys Vlasenkof645e152017-07-18 03:23:07 +020035a=Z env | grep '^[ab]='
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020036echo "^^^a is not exported"
Denys Vlasenkof645e152017-07-18 03:23:07 +020037# but external command does get executed, and $? is not mangled (stays 42):
38(exit 42); a=Z env echo Visible:$?
Denys Vlasenko5b2cc0a2017-07-18 02:44:06 +020039
Denys Vlasenkof645e152017-07-18 03:23:07 +020040echo
41true; unset a
42echo Fail:$?