"mksh -v" should display mksh's version number, plus the attached chunk of text, onscreen

Bug #1366451 reported by Jason Spiro
14
This bug affects 1 person
Affects Status Importance Assigned to Milestone
mksh
Opinion
Undecided
Unassigned
mksh (Debian)
Opinion
Undecided
Unassigned
mksh (Ubuntu)
Opinion
Undecided
Unassigned

Bug Description

It's customary in the Unix world that "-v" or "--version" displays a program's version. If someone is logged into an Android device, you want to make it easy for them to find out which shell is installed. How can you do this? One way is to offer a "-v" option which will tell them the answer (and will also tell them mksh's version number).

May I suggest that, if the user runs "mksh -v", then mksh should echo the following to stdout, after which it should immediately exit.

--- cut here ---
mksh R50b+cvs
This is mksh, the MirBSD Korn Shell.

Homepage: <http://mirbsd.de/mksh>.

Copyright (C) 2002-2014 Thorsten Glaser.
This is open-source software; see <https://www.mirbsd.org/TaC-mksh.txt> for copying conditions.

This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
the utmost extent permitted by applicable law, neither express nor
implied; without malicious intent or gross negligence.

Jason Spiro (jasonspiro)
summary: - mksh -v should display mksh's version number, plus the attached chunk of
- text, onscreen
+ "mksh -v" should display mksh's version number, plus the attached chunk
+ of text, onscreen
Revision history for this message
Thorsten Glaser (mirabilos) wrote :

No.

• GNU --long-options have nothing to do with a Unix program.
• A flag to display the version is not historically customary in Unix programs.
  The adoption of -V (not -v which is verbose) is recent and not normally used.
• “mksh -x” is the same as running “set -x” in the shell, which means that the
  namespace for these options is defined by, mostly, POSIX/SUSv4, on which we
  will not infringe for something like that.

The Android user would just type “set“, or “echo $KSH_VERSION”.

The Debian or *buntu user would just type “dpkg-query -W mksh” or (more common but cuts off version numbers) “dpkg -l mksh”.

Changed in mksh:
status: New → Opinion
Changed in mksh (Ubuntu):
status: New → Opinion
Changed in mksh (Debian):
status: New → Opinion
Revision history for this message
Thorsten Glaser (mirabilos) wrote :

(And I’m not going to embed long texts like this in the binary. The embedded customers (Android, OpenWrt, FreeWRT, OpenADK, etc.) would not like that size increase.)

Revision history for this message
Jason Spiro (jasonspiro) wrote :

> A flag to display the version is not historically
> customary in Unix programs.
> The adoption of -V (not -v which is verbose) is
> recent and not normally used.

I stand corrected.

> GNU --long-options have nothing to do
> with a Unix program.

Touché.

> The Android user would just type “set“, or “echo $KSH_VERSION”.

Not all Android users are so good with Unix that they know they should do that.

> status: New → Opinion

Hmmm. How about this?

If the user runs "mksh -?", "mksh /?", "mksh -v", "mksh -V", "mksh -h", "mksh -H", or "mksh /h" -- or if the user enters the single word "help" at a shell prompt -- then perhaps mksh could echo:

--- cut here ---
mksh R50b+cvs
For help: <http://mirbsd.de/mksh>.

--- cut here ---

Then, if applicable, treat the "-v" or "-V" or "-h" or "-H" or "/h" as POSIX/SUSv4 require. So, don't terminate; instead, show the shell prompt and proceed as if the user had entered a "set" command. Or, look for an executable file in the root directory named "/h", try to launch it, and if it wasn't found, inform the user.

Revision history for this message
Thorsten Glaser (mirabilos) wrote : Re: [Bug 1366451] Re: "mksh -v" should display mksh's version number, plus the attached chunk of text, onscreen

Jason Spiro dixit:

>If the user runs

>"mksh -?"

This expands to a file in the current directory that begins with - and
has another byte after it.

>"mksh /?"

This expands to a single-byte file (or directory) under /

>"mksh -v"

This is already used by POSIX, see “man mksh”, under the “set” builtin.

>"mksh -h",

Same here.

>"mksh -V"
>"mksh -H"

These are in POSIX namespace, so we cannot really give them out.

>"mksh /h"

This tells mksh to run the script called “h” in the root directory.

>or if the user enters the single word "help" at a shell prompt

“help” is aliased to “man” in most beginner-friendly GNU/Linux
distributions, in /etc/profile usually.

>-- then perhaps mksh could echo:

No, it will not.

>mksh R50b+cvs

There is no such thing anyway… mksh just knows about
its $KSH_VERSION, and releases are a convenience (and
a point of testing).

>Then, if applicable, treat the "-v" or "-V" or "-h" or "-H" or "/h" as
>POSIX/SUSv4 require. So, don't terminate; instead, show the shell

Ugh. No!

And I say that any Android user absolutely needing to know
the shell version is able to run the “set” command.

bye,
//mirabilos
--
„Cool, /usr/share/doc/mksh/examples/uhr.gz ist ja ein Grund,
mksh auf jedem System zu installieren.“
 -- XTaran auf der OpenRheinRuhr, ganz begeistert
(EN: “[…]uhr.gz is a reason to install mksh on every system.”)

Revision history for this message
Jason Spiro (jasonspiro) wrote :

In comment #4, Thorsten Glaser wrote:
> “help” is aliased to “man” in most beginner-friendly GNU/Linux
> distributions, in /etc/profile usually.

Not in beginner-unfriendly environments, such as the Android command-line environment.

By responding to the word "help" with the 50 bytes of text I suggested, mksh could make unfriendly environments a little bit more friendly.

If I sent a patch which would add this functionality, would you consider accepting it?

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

Jason Spiro dixit:

>If I sent a patch which would add this functionality, would you consider
>accepting it?

No.

Nothing against your intent, or beginners, or something, but Android
is really not the OS one should be learning a Unix shell in.

And mksh is first and foremost a Berkeley Unix shell.

bye,
//mirabilos
--
21:41⎜«Tonnerre:#nosec» Do at least one thing every day which makes
     ⎜ inspirational quotes lovers sad

Revision history for this message
Jason Spiro (jasonspiro) wrote :

> Nothing against your intent, or beginners, or something, but Android
> is really not the OS one should be learning a Unix shell in.

You are correct. Still, if someone owns only a Windows box and an Android phone, they might end up starting their learning on Android anyway.

> And mksh is first and foremost a Berkeley Unix shell.

Fine. But today, I noticed that you also maintain the stock Android mkshrc[*]. :)

^ [*]. <https://android.googlesource.com/platform/external/mksh/+/master/mkshrc>

mksh takes up more than 100 KB, and typical new Android phones seem to include gigabytes of flash memory. I still believe Android could afford the bytes it would cost to include a "help" function in /system/bin/mkshrc which would display something like the following.

--- start of help ---

This is mksh, the MirBSD Korn Shell. You can use a shell to perform advanced administrative and troubleshooting tasks on your device. You can also use it to capture screenshots and screencasts.

To work with files and directories:
    See <http://www.cs.bu.edu/teaching/unix/reference/commands.html>.

To work with Android logs, packages, databases, screencasts, and the like:
    See <http://developer.android.com/tools/help/adb.html#shellcommands>.

If you have a question, comment, bug report, or suggestion:
    Please visit <http://android.stackexchange.com/>.

--- end of help ---

This would help new mksh users realize how many things they truly can do in an Android shell. For example, they might have had no idea that they could capture screenshots and screencasts using the command line; but a help message can inform them.

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

Jason Spiro dixit:

>mksh takes up more than 100 KB, and typical new Android phones seem to
>include gigabytes of flash memory. I still believe Android could afford
>the bytes it would cost to include a "help" function in
>/system/bin/mkshrc which would display something like the following.

This is actually a good idea. Please submit this directly to AOSP
through their Gerrit system.

>If you have a question, comment, bug report, or suggestion:
> Please visit <http://android.stackexchange.com/>.

Not bad, but maybe they should tag those questions [mksh] on SE
and I should subscribe that tag there. Also, a link to the mksh
docs may be appropriate.

>This would help new mksh users realize how many things they truly can do
>in an Android shell. For example, they might have had no idea that they
>could capture screenshots and screencasts using the command line; but a
>help message can inform them.

Agreed.

While I “maintain” mksh in AOSP too (every once in a while, when
I can build it), I’m also just submitting things there, so please
submit yours, add enh and me as reviewers, and I can +1 it.

bye,
//mirabilos

PS: Thanks for the effort!
--
Yay for having to rewrite other people's Bash scripts because bash
suddenly stopped supporting the bash extensions they make use of
 -- Tonnerre Lombard in #nosec

Revision history for this message
Jason Spiro (jasonspiro) wrote :

In various comments, Thorsten Glaser wrote:

> This is actually a good idea.

Thank you :)

> Maybe they should tag those questions [mksh] on SE
> and I should subscribe that tag there.

A lot of the people who type "help" might not actually have questions about mksh: they may instead have questions about how to use head, tail, grep, logcat, or other tools. People who have questions about mksh, and who are SE-savvy, can figure out how to tag the questions [mksh] themselves. And even poorly-tagged questions can be retagged later.

Also, it's hard to advise users how to tag their questions inside a small Help screen, especially if some of them have never used SE before. And, if we provide tagging instructions, it may make SE sound like a scary and restrictive place.

> “help” is aliased to “man” in most beginner-friendly GNU/Linux
> distributions, in /etc/profile usually.

Really? Which distros?

The "man" command on a line by itself, without specifying a desired manpage, is quite useless for a total newbie. "man ls" is obscure, and "man cat" is useless.

"man intro", which ships with many Linux distributions, is pretty useful for newbies, though the initial "DESCRIPTION" section at the top is obscure and may make them give up reading early on. (You can view "man intro" online at <http://man7.org/linux/man-pages/man1/intro.1.html>.)

But Android doesn't ship a "man" command.

> I’m not going to embed long texts like this in the binary.
> The embedded customers (Android, OpenWrt, FreeWRT, OpenADK, etc.)
> would not like that size increase.

Might you be willing to please embed the text in a function in <http://www.mirbsd.org/cvs.cgi/src/bin/mksh/dot.mkshrc?rev=HEAD> instead of in the mksh binary?

If there exists even one embedded customer who is unhappy with the size increase, they can simply cut it out of their distribution. I suspect, though, that nobody will mind.

Anyway, you're better at shell scripting than me. :)

> Also, a link to the mksh
> docs may be appropriate.

How's this?

--- start of help ---
mksh R50b

This is mksh, the MirBSD Korn Shell.

You can use a shell to perform advanced administrative and troubleshooting tasks.
On Android, you can also use it to capture screenshots and screencasts.

To work with files and directories:
    See <http://www.cs.bu.edu/teaching/unix/reference/commands.html>.

To work with Android logs, packages, databases, screencasts, and the like:
    See <http://developer.android.com/tools/help/adb.html#shellcommands>.

To view the mksh homepage and manpage:
    Please visit <http://mirbsd.de/mksh>.

To find out which version of mksh you are using:
    Enter this command: ( echo $KSH_VERSION )

If you have a question, comment, bug report, or suggestion:
    On Android: Please visit <http://android.stackexchange.com/>.
    On other systems: Please visit <http://unix.stackexchange.com/>.

--- end of help ---

Revision history for this message
Jason Spiro (jasonspiro) wrote :

By the way, do here-documents work okay on modern versions of Android? Or is there no place for mksh to write the required temporary files to make them work?

Revision history for this message
Thorsten Glaser (mirabilos) wrote : here documents with mksh on Android (was Re: [Bug 1366451] Re: "mksh -v" should display mksh's version number, plus the attached chunk of text, onscreen)

Jason Spiro dixit:

>By the way, do here-documents work okay on modern versions of Android?
>Or is there no place for mksh to write the required temporary files to
>make them work?

There is still no place. If you set (not even needed to export, but
exporting is better so subshells inherit it) $TMPDIR, it works. If
you are root, it works (I think).

The AOSP people sorta-promised me either to set $TMPDIR in the
launcher, or to give me an API I can use to query a directory
which is writable for the current user (home directory, most likely).
I have not received either, yet. You may want to prod them.

As I do not use an Android device myself, things are slow from
my side.

bye,
//mirabilos
--
>> Why don't you use JavaScript? I also don't like enabling JavaScript in
> Because I use lynx as browser.
+1
 -- Octavio Alvarez, me and ⡍⠁⠗⠊⠕ (Mario Lang) on debian-devel

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

enh dixit:

>probably related to
>https://code.google.com/p/android/issues/detail?id=66815. i think the

Right, similar issue.

>hard part is what to set $TMPDIR to.

Agreed.

If I get a C API I can just call, I would put it into main.c in mksh
(set TMPDIR to that value, unless we import it from the environment
already).

Otherwise, something should ensure that $TMPDIR is set whenever mksh
is called. Since the shell can be called various ways (during boot,
adb, from a local application), this is pretty complicated; I’d suggest
adding code to bionic which I can call might be easier.

>the AOSP x86 emulator is pretty fast, as long as you have hardware
>that lets you use kvm. just don't forget to supply the flag so the
>emulator takes advantage of it!

Hrm. I’ll have to see if linux-kvm works inside a linux-kvm VM.
IIRC, this works with AMD CPUs. What is the “magic invocation”
to build for that, instead of for emulator (which I used to be
as close to upstream as possible)?

bye,
//mirabilos
--
Yes, I hate users and I want them to suffer.
 -- Marco d'Itri on gmane.linux.debian.devel.general

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

Jason requested an explicit answer to https://bugs.launchpad.net/mksh/+bug/1366451/comments/9 and here it is:

The idea is ok, but you’ll have to take this up with the Android developers yourself and submit it to AOSP using their Gerrit instance. That’s all I ever do, too.

I could imagine an implementation like this:

function help {
 cat <<EOF
This is mksh, the MirBSD Korn Shell - $KSH_VERSION

You can use a shell to perform advanced administrative and troubleshooting
tasks. A Unix shell is also a scripting language good for little programs.
On Android, you can also use it to capture screenshots and screencasts.

To work with files and directories:
    See <http://www.cs.bu.edu/teaching/unix/reference/commands.html>.

To work with Android logs, packages, databases, screencasts, and the like:
    See <http://developer.android.com/tools/help/adb.html#shellcommands>.

To view the mksh homepage and manpage:
    Please visit <http://www.mirbsd.org/mksh.htm>.

If you have a question, comment, bug report, or suggestion:
    On Android: Please visit <http://android.stackexchange.com/>.
    On other systems: Please visit <http://unix.stackexchange.com/>.
EOF
}

This would in-situ replace the shell version, even easier than to ask the user to echo $KSH_VERSION themselves. I also used an http link, to save bandwidth (the other homepage link redirects to https). I also added a bit about scripting.

Revision history for this message
Jason Spiro (jasonspiro) wrote :

mirabilos, I wonder if you might be willing to please put some shell function like this into the dot.mkshrc in upstream mksh CVS? It seems to me a fairly uncontroversial change. Then, next time you push the latest mksh version into Android gerrit, perhaps you could include this change as part of the broader changelist.

Plus, then perhaps MirBSD mksh and Android mksh could end up shipping similar or identical "help" shell functions in their respective dot.mkshrc files.

function help {
        cat <<EOT
This is mksh, the MirBSD Korn Shell.
Version: $KSH_VERSION

You can use a shell to perform advanced administrative and troubleshooting
tasks, or as a programming language for writing small programs.
On Android, you can also use a shell to capture screenshots and screencasts.

To work with files and directories:
    See <http://www.cs.bu.edu/teaching/unix/reference/commands.html>.

To work with Android logs, packages, databases, screencasts, and the like:
    See <http://developer.android.com/tools/help/adb.html#shellcommands>.

To view the mksh homepage and manpage:
    Please visit <http://www.mirbsd.org/mksh.htm>.

If you have a question, comment, bug report, or suggestion:
    On Android: Please visit <http://android.stackexchange.com/>.
    On other systems: Please visit <http://unix.stackexchange.com/>.

EOT
}

Revision history for this message
Thorsten Glaser (mirabilos) wrote :

> mirabilos, I wonder if you might be willing to please put some shell function like this into the dot.mkshrc in upstream mksh CVS?

I’m not.

> It seems to me a fairly uncontroversial change.

No. As I said, “help” is very generic, and I know of distros aliasing it to “man” or “man man”. (SuSE 6.1 did that, for example.)
Also, generic names are… problematic. I’ve learned my lesson from when I added a “rename” builtin.

> Then, next time you push the latest mksh version into Android gerrit, perhaps you could include this change as part of the broader changelist.

Android mkshrc is independent of mksh/dot.mkshrc and completely separately maintained.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.