-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
cell sublanguage: unset -v 'a[0]' (ble.sh) #651
Comments
OK we may need to do dynamic parsing of
And maybe a few other places... @abathur also used this with It will parse Somewhere on the blog I called this the "cell sublanguage", oh yeah here: http://www.oilshell.org/blog/2019/02/07.html#appendix-a-minor-sublanguages |
#608 is the feature for nameref |
note: marked with two stars on #653 |
May relate to IR in #604 , e.g. |
@akinomyoga Another thing I wanted to ask is if you're using only indexed arrays for
Or if you're also using associative arrays? The latter is trickier
It doesn't like the quotes, and prefers bare word syntax, which is inconsistent with the rest of Oil (and bash to some extent) |
Thank you.
Yes, I searched in ble.sh source and it seems unset is currently only used for indexed arrays. But that's not intentional and I'm not sure if I will never use it forever. And, it is a little bit awkward that there is no means to remove a key from associative arrays.
Which version of Bash do you use? I tried with versions of Bash and found that the behavior was changed since 4.4. I think it was a bug of Bash. $ bash --norc # bash-4.4 or 5.0
$ declare -A A=(['foo']=bar)
$ declare -p A
declare -A A=([foo]="bar" )
$ unset -v "A['foo']"
$ declare -p A
declare -A A=() The safe way for unsetting an associative array element in Bash that should work with an arbitrary key is the following. I think Oil can support this form. $ declare -A d
$ key="a]b'c[d" # A key containing special characters
$ unset -v 'd[$key]' |
- unset -v - declare -n - ${!ref} Not done: print -v Addresses issue #651. Unrelated: add some ideas in stdlib/README.md
OK yes, I was testing on my machine which is bash 4.3. I did it through the spec tests and bash behaves consistently with associatve arrays for So I think we can probably do it, though I might start with just |
It's hidden behind shopt -s unsafe_arith_eval to avoid surprises like: untrusted='A[$(echo K)]' unset -v "$untrusted" The code still needs refactoring. Also add shopt -s strict_unset, though it's not used yet. Addresses issue #651.
Removed 'strict_unset' since we don't need it yet. Related to issue #651.
I use this construct in ble.sh. I could find some test case for this here and also some mentions on
unset a[0]
here, but it doesn't work with the current Oil. Is this a regression?The text was updated successfully, but these errors were encountered: