skarnet / execline

The execline scripting language
https://skarnet.org/software/execline/
ISC License
149 stars 19 forks source link

`backtick` doesn't set `?` #15

Closed ormaaj closed 1 month ago

ormaaj commented 5 months ago

Command substitutions in standard shells always set the special parameter ? as a side-effect, so it is generally possible to retrieve the exit status of a command while capturing output. AFAICT the backtick utility is just opaque and discards the status unconditionally.

The only practical workaround I know of currently is to replace backtick v { ... } with an equivalent pipeline { ... } withstdinas v wait -o { }. backtick is certainly much more concise and reasonable for simple tasks so it would be very convenient if the status returned by its wait() were exposed through ?.

skarnet commented 5 months ago

That's a good point. I'll see if it can be done without too much pain.

skarnet commented 5 months ago

Can you please try the latest git of execline and tell me if it's working for you? ? will be set if you deviate from the default -i, meaning there's a case where backtick's child crashes or exits nonzero, but backtick still execs. (By default, it only execs if the child succeeded, so setting ? makes no sense.)

emanuele6 commented 2 months ago

Now it does

ormaaj commented 1 month ago

it works! And now I use it lots.