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