Denys Vlasenko | 5b2cc0a | 2017-07-18 02:44:06 +0200 | [diff] [blame^] | 1 | unset a b |
| 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 | |
| 15 | # these should all fail (despite the same value being assigned) |
| 16 | # bash does not abort even in non-interactive more (in script) |
Denys Vlasenko | 5b2cc0a | 2017-07-18 02:44:06 +0200 | [diff] [blame^] | 17 | true; a=A |
| 18 | echo Fail:$? |
| 19 | true; readonly a=A |
| 20 | echo Fail:$? |
| 21 | |
| 22 | # in bash, assignment in export fails, but export succeeds! :) |
| 23 | # we don't mimic that! |
| 24 | true; export a=Z |
Denys Vlasenko | 38ef39a | 2017-07-18 01:40:01 +0200 | [diff] [blame] | 25 | echo Fail:$?; true |
Denys Vlasenko | 5b2cc0a | 2017-07-18 02:44:06 +0200 | [diff] [blame^] | 26 | #env | grep '^a=' |
| 27 | #echo "^^^a is exported" |
| 28 | export -n a # undo that bashism, if it happens |
| 29 | |
| 30 | export b |
| 31 | # this fails to both set and export a: |
| 32 | a=Z env | grep '^[ab]=' # command still runs |
| 33 | echo "^^^a is not exported" |
| 34 | |
Denys Vlasenko | 38ef39a | 2017-07-18 01:40:01 +0200 | [diff] [blame] | 35 | unset a |
| 36 | echo Fail:$?; true |