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

command exit and \exit don't work to suppress function/alias lookup in OSH, because exit is a keyword #2228

Open
9ao9ai9ar opened this issue Jan 10, 2025 · 5 comments

Comments

@9ao9ai9ar
Copy link

So I played around with command -V in OSH and noticed that among the special built-in utilities, break, continue, exit and return are actually shell keywords. This means that the following code won't work:

command return
\exit # Unless a function named `exit` is defined, but then it won't be right.

command without options can suppress alias substitution, shell function lookup, as well as special properties of the special built-in utilities (though this last functionality is not respected in some shells): https://pubs.opengroup.org/onlinepubs/9799919799/utilities/command.html.

exit may be aliased (even in OSH, though I don't think it's possible to invoke the alias instead of the keyword), but neither methods of suppressing alias substitution can be used on it.

Do you plan to implement this "quirk and bug" of bash and other POSIX-compatible shells?

@andychu
Copy link
Contributor

andychu commented Jan 12, 2025

Thanks for trying it

That is a known difference - https://oils.pub/release/latest/doc/known-differences.html#break-continue-return-are-keywords-not-builtins

We are "conceding to reality" on some of these differences, but it's prioritized by running real shell scripts

If you have an example of a real shell script it breaks, that will take priority

If it's a synthetic case, then it's lower priority

Right now the top issue is that our IFS algorithm needs to be rewritten, since that blocks some real shell scripts


There are some threads on Zulip about this too

https://oilshell.zulipchat.com/#narrow/channel/384942-language-design/topic/Fundamental.20reasons.20for.20OSH.20incompatibility

@andychu andychu changed the title Some special built-in utilities are defined as keywords and this breaks some code break continue exit return are shell keywords in OSH but not in other shells Jan 12, 2025
@andychu andychu changed the title break continue exit return are shell keywords in OSH but not in other shells break continue exit return are shell keywords in OSH, but not in other shells Jan 12, 2025
@9ao9ai9ar
Copy link
Author

I should have read the docs before posting - thanks for linking to it.

It's just used in my personal shell scripts, so nothing like a high profile real world use case.

I didn't know about the IFS incompatibilities - that would definitely also break my scripts.

@andychu
Copy link
Contributor

andychu commented Jan 13, 2025

No problem, it's useful to know that people ran into this in their own scripts!

Examples can help

Sometimes people test synthetic cases, which is also welcome, but it is lower priority

@9ao9ai9ar
Copy link
Author

The script I used, which is the same as the one in #2224, is now published in the linked pull request above. The less mainstream use of shell commands that encountered this issue can be seen in the init function and the initial block of code above it and download_file.

@andychu andychu changed the title break continue exit return are shell keywords in OSH, but not in other shells command exit and \exit don't work in OSH, because exit is a keyword Jan 16, 2025
@andychu
Copy link
Contributor

andychu commented Jan 16, 2025

OK yeah I can see that other people may use this idioms to suppress alias and function lookup

And there is probably a way to implement it in OSH which is not too hard ... we could make command exit and \exit work, I think

@andychu andychu changed the title command exit and \exit don't work in OSH, because exit is a keyword command exit and \exit don't work to suppress function/alias lookup in OSH, because exit is a keyword Jan 16, 2025
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

2 participants