-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
Try to parse and run ble.sh #653
Comments
#620 was the original issue, already addressed |
Two issues blocking parsing:
|
Note: can parse
|
Rules:
|
@akinomygoa On #640 I added a temporary hack
and there's only one remaining error:
If you want to use And it should take 30 seconds to build osh from head on most Linux machines, although you can also wait until the next release: |
Oh, I didn't notice your comment (but my user name is akinomyoga). I tried the latest commit which worked nicely! In testing I replaced the |
I'm currently trying to source # ble.osh
shopt -s parse_unimplemented
BASH_VERSION='5.0.11(1)-release'
BASH_VERSINFO=(5 0 11 1 release x86_64-redhat-linux-gnu)
set -o emacs
source "$(dirname "${BASH_SOURCE[0]}")/ble.sh" --attach=none 1. No line-editing mode by default (
|
This is great, thanks for all the patches! About the first one, I just changed something there, and I agree the behavior is odd, but I see bash and OSH agree (at HEAD):
Do you get a different behavior? I agree they are mutually exclusive but they both start off OFF. bash has a weird conceptual model but I think OSH copies it. |
Thank you for your comment!
The default value in Bash depends on whether Bash is started in a non-interactive session or an interactive session. When you use the form On the other hand, By the way, the line-editing can be turned off in interactive sessions of Bash. The setting is |
Ah OK I reproduced this with |
Good news. I think I could finally source 5. INCONSISTENCY: Cannot create an empty associative arrayOil rejects $ osh -c 'declare -A dict; dict=()'
$ osh -c 'declare -A dict=()'
declare -A dict=()
^~~~~
[ -c flag ]:1: Got -A but RHS isn't an associative array 6. NYI (not yet implemented):
|
Thanks this is very useful. I just fixed point 13 -- it was an unintentional divergence.
I'll respond to the rest a bit later. More bugs/testing is welcome! |
Also what's the difference between By the way I will merge failing spec tests even if there's no fix yet. Showing the difference is often 50% of the work. The way I find the relevant tests is to do |
There are three different states for variables in Bash. In addition, the "set" state can be categorized into two sub-states:
See the following test case for the behavior differences: # test5.sh
function is-declared() { declare -p "$1" &>/dev/null; }
function is-enumerated-by-declare() { declare | grep -q "^$1="; }
function is-enumerated-by-varname-expansion() { eval "printf '%s\n' \"\${!$1@}\"" | grep -q "^$1\$"; }
function is-enumerated-by-compgen () { compgen -v | grep -q "^$1\$"; }
function is-enumerated-by-compgen-arrayvar () { compgen -A arrayvar | grep -q "^$1\$"; }
function show-status {
local -a msg=(yes)
local f
for f in $(compgen -A function -- is-); do
"$f" "$1"
echo "$f: ${msg[$?]:-no}"
done
}
echo "[undeclared]"
show-status dict
echo "[declared]"
declare -A dict
show-status dict
echo "[set]"
dict=()
show-status dict $ bash test5.sh
[undeclared]
is-declared: no
is-enumerated-by-compgen: no
is-enumerated-by-compgen-arrayvar: no
is-enumerated-by-declare: no
is-enumerated-by-varname-expansion: no
[declared]
is-declared: yes
is-enumerated-by-compgen: no
is-enumerated-by-compgen-arrayvar: no
is-enumerated-by-declare: no
is-enumerated-by-varname-expansion: no
[set]
is-declared: yes
is-enumerated-by-compgen: yes
is-enumerated-by-compgen-arrayvar: yes
is-enumerated-by-declare: yes
is-enumerated-by-varname-expansion: yes Related to this, in the help-bash mailing list, I have heard about some script library that gives a default array content when the definition is not given by the application. I'm not sure if it is a good design, but in that library, the empty array is one of the possible configurations, so one needs to distinguish the unset state ( # library
declare -A dict
is-array-set() { compgen -A arrayvar -X "!$1" -- "$1" &>/dev/null; }
function initialize-lib {
if ! is-array-set dict; then
# default dictionary
dict=([left]=right [up]=down)
fi
}
# application
# ... set up dict here ...
initialize-lib |
I'm reorganizing the patch set of Although I have listed many points above, the highest priority for me is No. 5 Also, I have three additional items as follows: 15. Q: How can I get OSH version of the currently running instance in scripts?There are many differences between Bash and Oil, and also many differences among different versions of Oil. In order to provide the best implementation for each version, I need to get the version information of Oil akin to FYI: $ declare -p BLE_VERSION BLE_VERSINFO
declare -- BLE_VERSION="0.4.0-devel2+420c933"
declare -a BLE_VERSINFO=([0]="0" [1]="4" [2]="0" [3]="420c933" [4]="devel2" [5]="noarch") 16. NYI:
|
note: marked #537 as implemented above, will be out with next release |
OK I just fixed #660 I think we probably don't have |
Thank you for continually fixing the problems!
Also, I think we may consider the separation of the execution environment of the line editor and the user commands. Note: But
As I have already mentioned a little in #687, I'm now adding tests in Do you think a long list of NYIs useful for Oil? I have read #701 (comment) saying "Any spec tests that reveal a difference between Oil and other shells are accepted", but I'm hesitating because most of them are unlikely to be supported in Oil in the future. Or, maybe it doesn't matter if we confine such spec tests in |
Yes! Absolutely. Oil can do this, and that's one of the main differences vs. other shells. The interpreter is re-entrant and you could even run multiple isolated interpreters in multiple threads, and remove the I/O from some of them. We will have think of a good API for spawning another interpreter. Because ble.sh stlil has to access some of the original interpreters settings I think -- it's not completely isolated How about putting all the NYI features here? I'm curious what is left. I think https://github.com/oilshell/oil/wiki/Running-ble.sh-With-Oil I think it ble.sh uses a bash feature, we should try to either implement it or provide some alternative. It might take a long time to do it, but maybe we will get some help along the way too from other people interested. |
Also feel free to start As I said I don't mind if they are failing -- it's better to know about it than not to know about it. It might not be done for many months but that's OK. I hope other people will be interested and help. |
About this point, I guess I would say there are different categories:
So I guess if you make a short list of what's NYI (e.g. on the wiki or here), I can probably give you an idea of whether I think Oil should implement it. I think most things Oil should implement, even though we may not have time to do it right now. I guess A feature definitely can't be done until there's a spec test since I won't know how it behaves. In the case of |
Thank you! I tested about 40% of 26. NYI: Dynamic unsetWhen $ cat test.sh
function unlocal { unset "$@"; }
function check4 {
hello=global
local hello=local
echo $hello
unlocal hello
echo $hello
}
check4
$ bash test.sh
local
global
$
$ osh test.sh
local
$ 27. NYI: flags
|
Great thanks for the testing. I will look at all of them but here are some quick comments:
|
OK I fixed #705, thanks for the reports :) |
Summarizing. Redirect bugs
NYI
Comment on 35, I believe this is POSIX behavior for "special builtin". bash may implement under
|
For #26, the
I'm not sure if POSIX says anything about which behavior is right... |
Thank you for the comments! I moved the list to the Wiki page. Re: 27. NYI: flags rx in
|
Error | Non-InteractiveShell | Interactive Shell | Shell DiagnosticMessage Required |
---|---|---|---|
Special built-in utility error | shall exit | shall not exit | no1 |
Other utility (not a specialbuilt-in) error | shall not exit | shall not exit | no2 |
Command not found | may exit | shall not exit | yes |
POSIX XCU 2.14 Special Built-In Utilities - exec - EXIT STATUS (Boldface is by me)
EXIT STATUS
If
command
is specified,exec
shall not return to the shell; rather, the exit status of the process shall be the exit status of the program implementingcommand
, which overlaid the shell. Ifcommand
is not found, the exit status shall be 127. Ifcommand
is found, but it is not an executable utility, the exit status shall be 126. If a redirection error occurs (see Consequences of Shell Errors), the shell shall exit with a value in the range 1-125. Otherwise,exec
shall return a zero exit status.
Re: 26. Dynamic unset
For #26, the unset behavior, is ble.sh relying on this?
Yes. It uses this in several places. Also, the Bash idiom Freddy Vulto's upvar trick relies on this behavior. bash-completion
uses this trick.
There are two different behavior in shells:
Actually, the situation is more complicated. The behavior of Bash depends on whether unset
is applied to local-scope variables (variables defined in the same function) or dynamic-scope variables (variables defined in the contexts of callers). Dynamic in the following table means to remove the cell, and static to set Undef
.
Shell | Local-scope variables | Dynamic-scope variables |
---|---|---|
mksh , yash |
Dynamic | Dynamic |
bash |
Static | Dynamic |
dash /ash , zsh , bash (shopt -s localvar_unset ) |
Static | Static |
- Note:
shopt -s localvar_unset
is available from Bash 5.0.
I'm not sure if POSIX says anything about which behavior is right...
POSIX doesn't define local variables, so it doesn't define the behavior of unset
for local variables.
Implements a feature mentioned in #653 (ble.sh).
It matches bash, mksh, and yash now. Instead of dash/ash or zsh. Addresses an issue in #653 (ble.sh). However this makes some tests in test/spec.sh assign fail. See the "if 0".
However this also makes some other tests fail -- ones that I added based on a report by @mgree last year. It fixed a bug with "temp bindings":
I don't remember the details right now though... But it is even more complicated than local scope and dynamic scope, because you also have these "temp bindings" to worry about. Can they be unset and can they shadow vars higher in the stack?
This statement and the table below doesn't exactly match what I observe... maybe you can add some test cases below #24 in spec/builtin-vars.test.sh ? Is the bash 5.0 behavior with I will look at it more later but having a test case for exactly what's used in ble.sh will help. Does the behavior as of the last commit make it work? If so then I just have to remember what the other test cases were for. I think I made it match dash because it was a simpler rule to implement, and it wasn't for running any real code. |
This is the issue from Michael Greenberg, who is working on POSIX shell (Smoosh, the executable formal semantics). So even though POSIX doesn't have locals, it has temp bindings, and this also affects unset! I didn't refresh my memory of this fully yet, but I think we can work it out between these two issues ... this is why we have the test cases Looking at case 24 only, I think I went with that behavior because only dash and zsh agree. Every other shell disagrees to an extent. Since people rely on the bash idiom, it's probably better to change it to be closer to that, but I'm not sure exactly how. So yeah having the exact test cases for ble.sh will help, e.g. in |
Also add spec test for ${array[@]::}. Addresses an issue in #653.
BTW the case from ble.sh is The other ones are |
Why?
https://github.com/akinomyoga/ble.sh
The text was updated successfully, but these errors were encountered: