-
-
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
[word_eval] Fix ${#BASH_SOURCE}, ${BASH_SOURCE:offset:length}, etc. #726
[word_eval] Fix ${#BASH_SOURCE}, ${BASH_SOURCE:offset:length}, etc. #726
Conversation
This is a good fix, but I find bash's behavior very confusing... I'm tempted to allow I think the latter is always clearer, because of the confusion with Arrays are first class: https://github.com/oilshell/oil/wiki/Language-Design-Principles In fact maybe it's cleaner just to have This bug is more evidence that #604 would help, because the control flow of this function is pretty confusing. Let me think about it a little... Thank you for the fix! |
I created such an option in my private version of Oil for the purpose of testing |
OK interesting... off the top of my head I would say we should consider these two behaviors:
It depends on how much code the special case costs us ... BTW neofetch patched itse usage of I guess I would accept |
To clarify the intention: I don't think The user can opt into them with I was reading |
Unfortunately, all the 44k+ lines of
OK, I agree with that. And, when they are enabled by
Yeah. Even users who understand |
OK sounds good. Yes I actually "blamed" AT&T (as opposed to GNU) in a link off of the last blog post :) http://www.oilshell.org/blog/2020/04/release-0.8.pre4.html#appendix-a-more-bad-parts-of-shell
Another interesting thing is this Usenix '94 paper about ksh: http://www.oilshell.org/archive/ksh-usenix.pdf It was trying to be like Perl and Python -- e.g. ksh had GUI bindings and people would write applications in it. But I think they didn't do a good enough job on the language, so Perl and Python overtook it. Python was first developed in 1989 and bash is from 1985 or so, so they aren't even that different in age. I think Perl was around 1985 too. But Python was designed to be a language and that mattered. OK I will merge this and I think add some failing tests for |
OK I added a failing test so we don't forget about it: Feel free to change it / enhance it, etc. Thanks for the pull requests! |
This fixes the following issues:
${#BASH_SOURCE}
for array variables counts the number of elements instead of the number of characters of the first element.$ osh -c 'f1() { echo ${#BASH_SOURCE}; }; f1' 1
${BASH_SOURCE:offset:length}
are used to select array elementsset -u
doesn't detect undefined first elements with the scalar form$BASH_SOURCE
.