From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2118 invoked by alias); 29 Aug 2016 23:01:39 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 39119 Received: (qmail 14779 invoked from network); 29 Aug 2016 23:01:39 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f46.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(74.125.82.46):SA:0(0.0/5.0):. Processed in 0.335546 secs); 29 Aug 2016 23:01:39 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=FREEMAIL_FROM,SPF_PASS, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 74.125.82.46 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=S+CUWjKFof6bvBeaWXjGyQjgLiGjnWLwuiGoijHAYdI=; b=Dy0nkfdpDK6BGhjpbz5zZTKhb7QUc+tg6aq5T5W/2KrDd9Tx0c6nNOMt3Qwt2ckEiU J+UpnZN9j3+doGrWEdbnD4MhMBno0bZd7fpsSaGx3PsOVGgrywH8hJAjMfYgCjAB2Dmq dE6RjEjxBly4knCjdlld4X4VqvHXHu9PhM4VdXKLyGdAkCaBfo/JsR3VenaRnyMIISVN awdjRYV1ia7v5LRAmi6io5pXhc4lVond27tKjxDVDty0yZBBycJrHra8rtGlErBtMxkd OQUWCvsjQsd/e8HwxPtFRg10NNtyJr7bqoSYKWdfnqtaQEJ0UlCXxmsUc0w48RcEbJXQ uqOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to:user-agent; bh=S+CUWjKFof6bvBeaWXjGyQjgLiGjnWLwuiGoijHAYdI=; b=Ngmm5tr1I6rrlVzz8+EHKoLpvIjnDUANXfJQmlvSVt7kzY5t9SLj3olZw1iDSkPr/i 4t99xDJPpyx4wi9ikAxxFrSQMdN1CiDbDRxAtbgtqeVoJ+s4o+4t9STEOnFC8wrQOXxJ rFoaukkVNqr0Ma6spo0aG6fQ3Mt3X4Vgae91rXxc0YA6DIIRhr56b1ewUWbSanJe3fHs GB5XNs+2GdrErjQvU562FKpSnDlMYbCm0xPmdDluN6AzRWHOi1nmtGLtP6OIHXyNVzKa jCL3cGg9NdV+0sn+2PDDXWb9S1Vt1NapOckHLv5q8UNEUr+9UtOvkmfMzrCOV5FSzC4g IVvw== X-Gm-Message-State: AE9vXwMNZqb0iRFgqoM+uC4eHNT5cg/Shlk53+8fA+GBKfUjq/UxnKRN42qqnzd+dmIBmA== X-Received: by 10.194.139.34 with SMTP id qv2mr16089582wjb.50.1472485918410; Mon, 29 Aug 2016 08:51:58 -0700 (PDT) Date: Mon, 29 Aug 2016 16:51:56 +0100 From: Stephane Chazelas To: Zsh hackers list Subject: [PATCH] [bug] $SHLVL decremented for the last command of a subshell Message-ID: <20160829155156.GB17700@chaz.gmail.com> Mail-Followup-To: Zsh hackers list References: <20160822061723.GA7308@chaz.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160822061723.GA7308@chaz.gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) 2016-08-22 07:17:23 +0100, Stephane Chazelas: > (from https://unix.stackexchange.com/questions/304917/detect-when-zsh-is-running-within-the-subshell-of-another-shell) > > $ printenv SHLVL > 1 > $ (printenv SHLVL) > 0 > $ (printenv SHLVL;:) > 1 > $ (:;printenv SHLVL) > 0 > > > http://www.zsh.org/mla/workers/1999/msg02472.html > sounds like a potential culprit. [...] I think the change below should be enough (also condensed the 2 "if"s below (unrelated)): diff --git a/Src/exec.c b/Src/exec.c index 9b24d38..54ececc 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3694,14 +3694,12 @@ execcmd(Estate state, int input, int output, int how, int last1) restore_params(restorelist, removelist); } else { - if (!forked) + if (!forked && !subsh) setiparam("SHLVL", --shlvl); - if (do_exec) { + if (do_exec && !subsh && isset(RCS) && interact && !nohistsave) /* If we are exec'ing a command, and we are not * * in a subshell, then save the history file. */ - if (!subsh && isset(RCS) && interact && !nohistsave) - savehistfile(NULL, 1, HFILE_USE_OPTIONS); - } + savehistfile(NULL, 1, HFILE_USE_OPTIONS); if (type == WC_SIMPLE || type == WC_TYPESET) { if (varspc) { int addflags = ADDVAR_EXPORT|ADDVAR_RESTRICT;