Denys Vlasenko | 0eed355 | 2017-07-21 13:37:25 +0200 | [diff] [blame^] | 1 | unset a b |
| 2 | # |
| 3 | readonly a=A |
| 4 | b=B |
| 5 | readonly b |
| 6 | # readonly on already readonly var is harmless: |
| 7 | readonly b a |
| 8 | readonly | grep '^readonly [ab]=' |
| 9 | # this should work: |
| 10 | export a b |
| 11 | export -n a b |
| 12 | echo Ok:$? |
| 13 | env | grep -e^a= -e^b= # shows nothing |
| 14 | |
| 15 | echo |
| 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 |
| 19 | true; (a=A) |
| 20 | echo Fail:$? |
| 21 | true; (readonly a=A) |
| 22 | echo Fail:$? |
| 23 | |
| 24 | echo |
| 25 | # in bash, assignment in export fails, but export succeeds! :) |
| 26 | # we don't mimic that! |
| 27 | true; (export a=Z) |
| 28 | echo Fail:$? |
| 29 | #env | grep '^a=' |
| 30 | #echo "^^^a is exported" |
| 31 | export -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 | |
| 42 | echo |
| 43 | # ash: this fails *silently*, bug? bash says "cannot unset: readonly variable" |
| 44 | true; unset a |
| 45 | echo Fail:$? |