From: OG Code Poet <ogcodepoet@gmail.com>
To: Roman Perepelitsa <roman.perepelitsa@gmail.com>
Cc: zsh-users@zsh.org
Subject: Re: Read/write multiple histories from non-interactive shell
Date: Wed, 15 Feb 2023 22:14:43 -0800 [thread overview]
Message-ID: <CADmFDtXhU1Nff0K06R_5BK_m_9AUNFGSRh1bM-wCucYprxj+Kg@mail.gmail.com> (raw)
In-Reply-To: <CAN=4vMrLbpuTe6AP2A-HkbFTzuvsH29tnDMJ7M2H-GxK_rvT5g@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 2100 bytes --]
I wish it were that simple a case. Turns out there are other cases where a
script that runs well in non-interactive move would crash when run with -i.
In my case it was trap for TSTP. A workaround is to put ``setopt
nomonitor``, which in my case is valid as I don't need job control. Though
what is interesting is that the script ends with an error code of 0. Anyway
the exit behavior itself is inconsitent. Try two experiments: 1) add ``trap
'foo=1' TSTP`` as first line of your sample code in this thread. This time
zsh would complain but not exit. 2) add ``trap 'foo=1' TSTP`` to your
function read-field() or in while loop. This time zsh will exit with error
code 1. In my script, where the trap is somewhere in 3 or 4th level
function in the stack, the script exits with exit code 0.
Here's the link to relevant part of code:
https://github.com/zsh-users/zsh/blob/b1533066ca7d50c88b37ce72093c12cf19807818/Src/signals.c#L921-L924
```
if (jobbing && (sig == SIGTTOU || sig == SIGTSTP || sig == SIGTTIN)) {
zerr("can't trap SIG%s in interactive shells", sigs[sig]);
return 1;
}
```
I figured ``setopt nomonitor`` disables jobbing, and bypasses executing
that if block.
On Mon, Feb 13, 2023 at 1:43 AM Roman Perepelitsa <
roman.perepelitsa@gmail.com> wrote:
> On Mon, Feb 13, 2023 at 9:57 AM OG Code Poet <ogcodepoet@gmail.com> wrote:
> >
> > My larger script misbehaves and exits with 0 before it could
> > complete if I replace #!/usr/bin/env zsh with #!/usr/bin/env -S zsh
> > -fi or #!/usr/bin/env -S zsh -i.
>
> You might want to try to figure out why.
>
> > Is there a restriction on starting any existing functional zsh
> > program with -fi? Put another way, are all non-interactive shell
> > scripts guaranteed to function when shebang is changed to
> > #!/usr/bin/env -S zsh -fi??
>
> If you put something like this in a script, it won't work the same way
> in interactive shell:
>
> [[ -o interactive ]] && exit
>
> In general, if your script needs interactive features, it makes
> perfect sense to use an interactive shell as the interpreter.
>
> Roman.
>
[-- Attachment #2: Type: text/html, Size: 2857 bytes --]
prev parent reply other threads:[~2023-02-16 6:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-13 7:35 OG Code Poet
2023-02-13 7:43 ` Lawrence Velázquez
2023-02-13 8:18 ` Roman Perepelitsa
2023-02-13 8:57 ` OG Code Poet
2023-02-13 9:43 ` Roman Perepelitsa
2023-02-16 6:14 ` OG Code Poet [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CADmFDtXhU1Nff0K06R_5BK_m_9AUNFGSRh1bM-wCucYprxj+Kg@mail.gmail.com \
--to=ogcodepoet@gmail.com \
--cc=roman.perepelitsa@gmail.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).