From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3654 invoked from network); 16 Feb 2023 06:15:49 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Feb 2023 06:15:49 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1676528149; b=cQE4O0dmJVGQAOB0PIdUViqDPBgCbfRMycKzKJvbXsaBt9Sx1WRK7jIMxOIEMLz9HKEmDdCWAG OgvEt9Tf4vekE3jVlJJtQO3A9UMRaCH+WFVFiZLzZ+lkYMEWIpt/+uCkwuvo7TSbgut5eKcSbR HGKDBCJLZ+Twzv30Wo/tte236BK27ZTtCYNY/H/p6DCx/c5wfJyhbsUh8tLyP9vqPZETIaxinI lky9/NbKdCvCRrtjTWm8n2M4HerwHwxJjuVOK+RSfhIvFVTPqyVojEFnQq/9d0FO2kPKVKhUWA dj/uJyTkAblhO/GBJkXvAgdvqWuHuPifjTsbYiw6ReSJFw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f45.google.com) smtp.remote-ip=209.85.217.45; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1676528149; bh=ikEoxDra82omU0ZMq3Ushw/f72/EhjVVd3WKgXr5MuU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=aQs9atkI+rhFcOTp6nCi/X4meI9IT++zMp5z4DMGAwQPuoHPHAN9fkq0JK6nUy9H34aqui3AgJ LTKR2QYNtY/s84vaBtoz+0KZ0umPS45LKGlCZ0/XuAYMgLtEe7Tp4l2B4KRlmNtLwoSJXNTwGO a+0R8T3t+PgwztZmNkKDesOb+c+o3QdRZV6GCyaSkiInu+FzoVwnTRpINawHKlKcMH096Y+UHJ lY1LrFqzhLzEvKozRKNqerl9thf0Z/oZSkYQT/969Iey7Pj2UlLb5Xi4o1U9XaG/1dkm/QA7Ix 7V8XYpfDI57EUqhf0i2yAb0W9MGXorn0uZpIFttwv4xlkg==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=wJDvW5DaG2huzwIbcRWSe+Ik7DprCj8NhgQhBfHBYZs=; b=KaF2GyNcbTNH6ZKmntZe2pFu+R vRJhpiItXeZLSzw12QcuqsnXZndl9eEBNvd1U06le7b9ANHRX1MoVcHEgBoS+iPNdAOoPyn8BDC3w 2nahdtdVhOisfLPcLsWXVgSH6thOggLDdGPH2OG1uxbHnfH+bSXubM6FyuvTAimRu/XmmE1a/f7JC ROscf5d1deVqs5FWUZZ7bg6IgAbuPdAQcn8OTQ+qTeJGh7R26R2b6I9RdjoTCBPj+MyjmP8/iaZmz Pd08kguAS5Ub4spokGwXLT2Sg2ajFIEmkoQVCyvjMwdYe8HgN2UWM6sj2mHh+zvCL5Aft+7IGs/N8 crO2rPuA==; Received: by zero.zsh.org with local id 1pSXYZ-000Khg-Kb; Thu, 16 Feb 2023 06:15:47 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f45.google.com) smtp.remote-ip=209.85.217.45; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f45.google.com ([209.85.217.45]:46702) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pSXXj-000Jye-Bh; Thu, 16 Feb 2023 06:14:55 +0000 Received: by mail-vs1-f45.google.com with SMTP id q190so861913vsa.13 for ; Wed, 15 Feb 2023 22:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=wJDvW5DaG2huzwIbcRWSe+Ik7DprCj8NhgQhBfHBYZs=; b=R5pfp3A5TAUNu0rfn/Tk8Z5pSQm+kLor+JEPI8+3LQCDIdFQduG4yP1VdUnWHKDtbn FlUVwdP0DxCmDTSbpNHfy5QmGT2dHPqElTIpZSE7VAC4Pl+UgUYi6zzWKhX86SYOhSx0 WhA3wayHh4ko8JAexZoF3m1WA6mv+uiVVecGepZWcxdt32cobpT4sP8y6kXeKwJkxBz9 8R7+dH8jQcpEVehhRw8GTkVPmycbl0l7JvDvoxJTC/iY2AxdFT4gl0ezdNX0UNXSBxQH /wg9uEMZW2ffIMhp6WDAaggN+QEpAkNiLev7pKVDzANkYQoGG75+ZZ5ZhwUZll5xordD fBCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wJDvW5DaG2huzwIbcRWSe+Ik7DprCj8NhgQhBfHBYZs=; b=SUOLQ1csm7xnayVvBZH/5QKG9YQ95JMegGzzxBOXBvhcfA9mZA0iZzUmn78gYtcs7L FQoatlvXjnrq3xtiVnhV0jlGOseYFVPrf4g5lB/j0VV5fDsf5XWV2p9B7HfYAaTRi9QI xd78kZf4i0xaua8gFkP5ug2RqU3CSpRqvIw56S6baAi2IihiTir5zdPaJHMJyWG5ZV75 BfMsxhEoHT1d/SAu1zCjRVk7Cgg4TeWGt5eglEp7wmZf4nU6UuxVO45Vwa5zLIipmwfp 41aG3QCfKoPWY+ocAwOqr0DIAL9EXKL/Iqewzmoc4HMLZmsEoU6tXH8/7YpVYGe9Nem/ F0mg== X-Gm-Message-State: AO0yUKUuQcH00REkR4wUQobaB0YGLXXPt0CELcCXFlaa3WPxLLInGuwz WNpu2t8geOebJBy9vemfhsle27P6wFEv4/w/TKQ= X-Google-Smtp-Source: AK7set/wSWOFhrQxgJ+uDmQJdWQzAbFve0d42A1Xxt/bFbEngHRMiIx4AkW+bIbvDMMxfHXdQqSTJVVfNdqyypITInw= X-Received: by 2002:a67:f853:0:b0:3ce:dcbc:23a5 with SMTP id b19-20020a67f853000000b003cedcbc23a5mr859189vsp.71.1676528094099; Wed, 15 Feb 2023 22:14:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: OG Code Poet Date: Wed, 15 Feb 2023 22:14:43 -0800 Message-ID: Subject: Re: Read/write multiple histories from non-interactive shell To: Roman Perepelitsa Cc: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="000000000000813e9c05f4cb1d2c" X-Seq: 28945 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: --000000000000813e9c05f4cb1d2c Content-Type: text/plain; charset="UTF-8" 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 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. > --000000000000813e9c05f4cb1d2c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I wish it were that simple a case. Turns out there are oth= er 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 cont= rol. 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=3D1' TSTP`` as first line of your sample code in= this thread. This time zsh would complain but not exit. 2) add ``trap '= ;foo=3D1' TSTP`` to your function=C2=A0read-field() or in while loop. T= his time zsh will exit with error code 1. In my script, where the trap is s= omewhere=C2=A0in 3 or 4th level function in the stack, the script exits wit= h exit code 0.

Here's the link to relevant part of code:
```
=C2=A0 =C2=A0 if (jobbing && (sig =3D=3D SIGT= TOU || sig =3D=3D SIGTSTP || sig =3D=3D SIGTTIN)) {
=C2=A0 =C2=A0 =C2=A0= =C2=A0 zerr("can't trap SIG%s in interactive shells", sigs[s= ig]);
=C2=A0 =C2=A0 =C2=A0 =C2=A0 return 1;
=C2=A0 =C2=A0 }
```

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<= br> in interactive shell:

=C2=A0 =C2=A0 [[ -o interactive ]] && exit

In general, if your script needs interactive features, it makes
perfect sense to use an interactive shell as the interpreter.

Roman.
--000000000000813e9c05f4cb1d2c--