Re: s6-test -v does not work for variable "!"
So there are several things. - "=" is not a legit envvar name: envvar names cannot include a '=' character. "!" is absolutely a legit envvar name, though, and execline uses it with commands such as background or pipeline. - execline does not understand single quotes. '!' will translate into the word "'!'". So, don't use single quotes in execline, ever. Only double quotes. - It is a peculiarity, and *the* non-posix behaviour, of s6-test, that when an argument starts with a backslash, the backslash is ignored, and the remainder of an argument is used as data, and never as an operator. s6-test uses this to disambiguate, instead of relying on the total number of arguments (and doing unspecified, unpredictable things when given more than 4 arguments). For instance, "s6-test -r = -r" will fail with a parsing error (which is non-conforming to the "test" specification), because there is a parsing ambiguity with "-r =", and s6-test does not use the fact that there is another argument behind "=" to lift the ambiguity. - "s6-test -v !" sounds like a simple case, but it's not, because "!" is a valid operator for s6-test, and s6-test does not look past "!" to see there are no further arguments and "!" cannot be an operator. So it fails for the same reason described above. The way to avoid that is to backslash the argument: "s6-test -v \!" - execline uses \ as a quoting character, so when writing an execline script, you need to double the amount of backslashes that you want to appear in your argv. Here, you want one backslash before the "!", so you would write s6-test -v \\! and that should work. - I know that the s6-test behaviour is non-conforming when you provide fewer than 4 arguments, and is non-intuitive and annoying, especially when "test" just works. But it is *mighty hard* to implement the POSIX disambiguation method without exploding the code size. Doing it would take some real serious effort and probably double the size of the s6-test source code - and it would *still* need to provide a different way to disambiguate for 5 arguments or more, because s6-test explicitly supports an infinite number of arguments. (Or, rather, as many as fit into your argv.) This is the very reason why I didn't bother making it a conforming "test" implementation: the POSIX requirements require ad-hoc operator priority rules that do not fit the shift-reduce engine *at all* and that are super difficult to implement cleanly. - I wrote s6-test when I was first reading the Dragon Book on compiler implementation, specifically the chapters on parsing, as an exercise to check I understood how pushdown automata worked. s6-test and s6-expr are prime examples of pushdown automata. So that is why 1. I needed a shift- reduce disambiguation method that meshed well with the engine, which the POSIX test disambiguation method is not, and 2. the code may not be intuitive, because it's the most "computer science academia" thing I've ever written. :) (Yes, that includes the execline/mdevd/... parsers. These parsers are table-driven parsers, aka deterministic finite automata. That's *simple*. The tables look intimidating, but the code itself is very straightforward. Pushdown automata are a different story, you really need the theoretical background to wrap your mind around them.) TL;DR: s6-test is not test, please use s6-test -v \\! in your execline scripts, and basically prepend any argument that looks like a possible test operator with two backslashes (because execline eats one, and a shell would as well). -- Laurent
Re: s6-test -v does not work for variable "!"
On 9/5/22 22:15, alice wrote: On Mon Sep 5, 2022 at 10:08 PM CEST, Songbo Wang wrote: #!/usr/bin/execlineb -P export ! 0 s6-test -v '\!' changing this to s6-test -v \\\! works as expected. Thanks for the reply. It indeed works. But there is one thing I find counter-intuitive: s6-test expects to see an escaped ! while export doesn't. For example this exits 1: #!/usr/bin/execlineb -P export \\\! 0 s6-test -v \\\! quoting is different in execline, i think there was more written in some documentation for the specifics, but i think it needs to both escape the ! and the \ , so it's three levels of > as a bonus, that also works in normal shell (no quoting in both places) -- Songbo Wang (汪嵩博)
Re: s6-test -v does not work for variable "!"
When the environment modification takes place with export is unintuitive; try ``` #!/usr/bin/execlineb -P export ! 0 foreground { exit } s6-test -v '\!' ```
Re: s6-test -v does not work for variable "!"
On Mon Sep 5, 2022 at 10:08 PM CEST, Songbo Wang wrote: > On 9/5/22 20:57, alice wrote > > s6-test -v '\!' > > seems to work for me, tested with > > env !=1 s6-test -v'\!' > > and without the env. maybe i'm misreading it? > > > Your example works for me on bash, but I just tested by the following > execline script > > #!/usr/bin/execlineb -P > exec -c s6-test -v ! > > which gives a parse error to me. Double quoting the ! gives the same > error. Single quoting eliminates the error, but doesn't seem to work > correctly: > > #!/usr/bin/execlineb -P > export ! 0 > s6-test -v '!' > > exits 1. Backslashing ! doesn't work, double quoted or not. Single quote > works, but same > > > #!/usr/bin/execlineb -P > export ! 0 > s6-test -v '\!' changing this to s6-test -v \\\! works as expected. quoting is different in execline, i think there was more written in some documentation for the specifics, but i think it needs to both escape the ! and the \ , so it's three levels of \ as a bonus, that also works in normal shell (no quoting in both places) > > exits 1. > > I wonder if I am stuck in some intricate no-go land of execline or > s6-test... > -- > Songbo Wang (汪嵩博)
Re: s6-test -v does not work for variable "!"
On 9/5/22 20:57, alice wrote > s6-test -v '\!' > seems to work for me, tested with > env !=1 s6-test -v'\!' > and without the env. maybe i'm misreading it? > Your example works for me on bash, but I just tested by the following execline script #!/usr/bin/execlineb -P exec -c s6-test -v ! which gives a parse error to me. Double quoting the ! gives the same error. Single quoting eliminates the error, but doesn't seem to work correctly: #!/usr/bin/execlineb -P export ! 0 s6-test -v '!' exits 1. Backslashing ! doesn't work, double quoted or not. Single quote works, but same #!/usr/bin/execlineb -P export ! 0 s6-test -v '\!' exits 1. I wonder if I am stuck in some intricate no-go land of execline or s6-test... -- Songbo Wang (汪嵩博)
Re: s6-test -v does not work for variable "!"
On Mon Sep 5, 2022 at 8:42 PM CEST, Songbo Wang wrote: > Hi, > > I've been recently playing with execline scripts and found out that > s6-test -v ! s6-test -v '\!' seems to work for me, tested with env !=1 s6-test -v'\!' and without the env. maybe i'm misreading it? > is not able to test if the ! environment variable is set. I guess it is > because s6-test would also need to handle expressions like "x != y", but > the code is too mystic for me to understand (by the way, s6-test fails > to test = too, but I don't even know if it is a legit envvar name). > > I think it is reasonable to use ! as an envvar, as it is set by some > execline utilities, e.g. background, wait. > > Cheers, > -- > Songbo Wang (汪嵩博)