Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set -u is respected for var refs to arrays, unlike in bash #1034

Closed
andychu opened this issue Dec 4, 2021 · 2 comments
Closed

set -u is respected for var refs to arrays, unlike in bash #1034

andychu opened this issue Dec 4, 2021 · 2 comments

Comments

@andychu
Copy link
Contributor

andychu commented Dec 4, 2021

Nix uses a lot of this, see

https://oilshell.zulipchat.com/#narrow/stream/121539-oil-dev/topic/Oil-Nix.20Meeting.3F

related to #881

Probably start spec/nix-idioms.test.sh

andychu pushed a commit that referenced this issue Dec 5, 2021
@andychu andychu changed the title Test out nameref semantics and document them more (e.g. for Nix) Test out var ref semantics and document them more (e.g. for Nix) Dec 5, 2021
andychu pushed a commit that referenced this issue Dec 5, 2021
Part of #1034.

It used to look like

    [ var ? ]:1: fatal: Undefined array 'preHooks'

Now it looks like

    [ var 'hookSlice' at line 6 of [ stdin ] ]:1: fatal: Undefined array 'preHooks'
@andychu andychu changed the title Test out var ref semantics and document them more (e.g. for Nix) set -u is respected for var refs to arrays, unlike in bash Dec 8, 2021
@andychu
Copy link
Contributor Author

andychu commented Dec 8, 2021

Summarizing:

https://oilshell.zulipchat.com/#narrow/stream/307442-nix/topic/var.20ref.20idiom

I tested it out, and this rule where set -u is ignored only applies for arrays. It doesn't apply for regular string vars

So 2 ways bash is inconsistent:

  1. static reference vs. var ref
  2. string vs. array

It is possible to hide it behind strict_array, but deferring now because Raphael wants to improve the program by defining variables

@andychu andychu added the nix label Dec 22, 2021
andychu pushed a commit that referenced this issue Dec 22, 2021
For both #1034 and #1047, exposed by Nix.

mksh agrees!  So this is higher priority.
@andychu
Copy link
Contributor Author

andychu commented Mar 29, 2024

I think this was fixed along with #1884

test/spec.sh append passes all cases

@andychu andychu closed this as completed Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant