rmyorston / busybox-w32

WIN32 native port of BusyBox.
https://frippery.org/busybox
Other
678 stars 125 forks source link

Error out on --version #457

Open ale5000-git opened 3 hours ago

ale5000-git commented 3 hours ago

Scripts may want to check the shell version by using: $0 --version or $SHELL --version

BusyBox doesn't support it but it is an upstream issue.

Now the biggest problem is that instead of error out it open an interactive shell and this freeze the script. Could you please error out on --version? (with a clear message: ash: unrecognized option '--version')

Maybe also error out on --init-file since having the command illusorily working without being supported is annoying.

avih commented 3 hours ago

Scripts may want to check the shell version by using: $0 --version

It may want to do many things, but this specific one would not be wise, because login shell typically has - prepended, e.g. in a bash login shell $0 is -bash, and you can't run it because there's no -bash in $PATH.

or $SHELL --version

Again, not wise, because that's not standard.

Also, shells gain features and bugs over the years, so the fact that you think you know what the shell is doesn't guarantee that the feature you want to use would work.

There's no obvious method to identify busybox-ash or dash or freebsd or netbsd (a)sh, and same for many other shells.

You can sort of identify bash using $BASH_VERSION, and zsh using $ZSH_VERSION, but if you really want bash then use a #!/bin/bash shebang instead of running as a standard shell and wanting to use non standard features.

If you want to use non standard feature which you're not sure if they exist, then your best course of action is to test the specific features in your script before you try to use them.

The solution is not to add features which makes it easier to identify the shell, because this is a rabbit hole that no one wants to get into.

ale5000-git commented 2 hours ago

Actually I only use it to display shell info and not for the code itself. I haven't asked any new option but just to display error (and exit with an error code) for unsupported options.

Usually I code scripts to work on all shells and all OSes in the world (at least the idea is this).