Ciprian Dorin Craciun dixit:

>    (I hope this wasn't already discussed, but from a quick search of
>the mailing list archive I don't think so.)

No, it wasn’t.

>would behave like `-s`, but which would instead have an argument
>specifying the file descriptor number to read the script from (instead
>of stdin).  

I wonder at the use cases for this. Sounds pretty marginal to me,
but maybe you can explain on it a bit.

>Moreover, just like in `-c` case, the following extra
>arguments are treaded like `$0`, and so forth.

JFYI, -s already behaves like that (except the first argument is
used as $1 not $0).

>    My RFC is the following: how about having a flag, say `-S`, that

Top-level shell options are shared with the set builtin, and I’m
*very* reluctant to add any more. Let’s discuss this a bit more.

>    * using `mksh /dev/fd/5`, but which unfortunately puts `$0` as
>`5`, and must be overridden in the script;

What do you want in $0 instead? Following -s, I’d put mksh there.

>    * using `mksh -c '. /dev/fd/5' script-name`, which seems clumsy;

It may seem clumsy but is probably perfectly serviceable…

>    * using `mksh -s` and playing with duplicating file descriptors;
>`mksh` reads the script directly from `0`, which means that if I
>replace `0` inside the script `mksh` will start reading there instead,
>thus making impossible to have a proper stdin;

Right. This was my first idea, but it’s not a working solution
to your problem for that reason, indeed. I occasionally fall
into that trap too… echo read foo | mksh -s…

>    However (most) all of them require the use of `/dev/fd` (or
>`/proc/self/fd`), which wouldn't work in case these two file systems
>aren't mounted, such as is the case in early booting where I intend to
>use this feature.

I see. Maybe we can find another way around this yet… do you
have any concrete use case for it yet, maybe something already
written that uses it?

>    P.S.: If the developers are willing to accept a patch, I could
>provide it, as I've studied the source code and doesn't seem too hard
>to produce it myself.

We’ll see… it _is_ a bit tricky around corner cases, like the
option namespace, and that we cannot use the SSTDIN source type
because it’s handled specially further down in the shell (for
precisely the reason that it occupies fd#0), and you don’t want
it to use a file.

I admit I’d like to find a solution that doesn’t involve patching
mksh first; if you’re okay with that, that is.

I *was* thinking of extending the “exec” builtin to be able to
set argv[0] to some random string, too… but this would, again,
require /dev/fd. If you’ve got tmpfs (from you mentioning /proc
I assume you’re on GNU/Linux?), we can use that.

bye,
//mirabilos
-- 
<mirabilos>    │ untested
<Natureshadow> │ tut natürlich
<Natureshadow> │ was auch sonst ...
<mirabilos>    │ fijn ☺

Reply via email to