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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 7716 invoked from network); 25 Jan 2021 13:19:23 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Jan 2021 13:19:23 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1611580763; b=uDhe0YHew+c5GLvc+cy13QfXP1VpkGY1FkCSnX6+GMsz3Znkau7Dm9uqJHYD5l7zpiH9rZ5n+6 F7qrjRv/NNDdtMnM0rjbiuTV7HVMfQn5rcSyE9Wo3yTu8wnNC+Adf70evSJ+1TSbe/YkV5mr69 obvLfKpZFOo239IfRKy1Hk6NCacHeWjAAnhk0R/nHix2SP5x2ZDk65SlpS/RL4e8oUkrExRJtB A7WUH8+Swq+2StAUudMW0BHDfmuwaBbneBeZm0qABkCJM4yQrQVJ7cJZKiLjxF84rI7A75wQsm 4e0x08wNV7z6e0NpmlB+ZKRfjqpR1ZThH6cBkH1CNJ7XMg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1611580763; bh=9njozCI0nwMcrltSHh/OPoE/TKiVA2QAMkzFyDmI5K0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature; b=B7idcUh1zx1sQAbGqHIpOZSfpUmghR90nTr7fVpCmC9by4xw3InLfRzSe7bOtmmrsYHWcxNgsa XjoUFt1NhcVkzTkNosj5wWovpTnaz6TgeVU59Ky8jacyikaFDSH8s9LgzPpTXcR95UoI68HJYm phUQsB04fpM0F6QpcrvjdSyiT2A+IYr8aTD9QB/n/bRT2IeIve0A7LsAmzcJLhFezgcAHK3uY4 2R8SONE4x4M3hUDbb/yNaKKtIwqmpIbZEoybBFGMDL1pAHE4v/u8IXtdYYib0FSSmNkjYtsVWR nFSzQGCHFrp2sV9WnBIBR92fpPzdsTbaQ1wM9SdnMbng9Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=oXf+lrcOHQN/zVvKgupF1QVfd26pVYOTm7nvQl+0S3c=; b=ACPF36HWhavIrSiCXxcDBB+RTD 6xQXTyXGWz9EbFAfsCT93tq0CFR0gTqZBBuyUYDs7o/oxhC5iyHe6dor9N7scG+J36lF1IFMjyfMC BcizMxv14fJHevhxwJTwsEN8Zo0pWGqOyU5sQjZ7GhyiUAQc5fVJanYdOm+al3MgX+JAaaatJCE21 IVsxjHI8r4HkI1DJeCZ3FWmKyWX62EfBSQcdFgkpOJBOuFUU+reXy1gkheGv8bsdnPBmDLBb2AjJn QyXYKfInFR5nZ0CnPZXLFYUshVBDY+1AOmkJAddUyo3JhMz7HfKyplGpv8ejWKQHq7QbM3+JXreuI HkGpvE6A==; Received: from authenticated user by zero.zsh.org with local id 1l41m2-000EFz-Vj; Mon, 25 Jan 2021 13:19:18 +0000 Authentication-Results: zsh.org; iprev=pass (relay6-d.mail.gandi.net) smtp.remote-ip=217.70.183.198; dmarc=none header.from=chazelas.org; arc=none Received: from relay6-d.mail.gandi.net ([217.70.183.198]:44623) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1l41lV-000DsJ-Fd; Mon, 25 Jan 2021 13:18:47 +0000 X-Originating-IP: 94.10.127.123 Received: from chazelas.org (unknown [94.10.127.123]) (Authenticated sender: stephane@chazelas.org) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 95441C0009; Mon, 25 Jan 2021 13:18:44 +0000 (UTC) Date: Mon, 25 Jan 2021 13:18:43 +0000 From: Stephane Chazelas To: Ray Andrews , Zsh Users Subject: Re: capture stderr in command substitution Message-ID: <20210125131843.apg23u4xe3ru22pk@chazelas.org> Mail-Followup-To: Ray Andrews , Zsh Users References: <1eb9835c-3911-d4ea-6456-d9ad52ceffea@eastlink.ca> <20210125123800.5vn5zvtn5sho2rim@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20210125123800.5vn5zvtn5sho2rim@chazelas.org> X-Seq: 26413 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: Archived-At: 2021-01-25 12:38:00 +0000, Stephane Chazelas: > 2021-01-24 11:45:31 -0800, Ray Andrews: > > $ var=$(command) > > > > ... but $var doesn't pick up errors.  Can it be forced? > [...] > > var=$(cmd>&2) > > like in any Korn/POSIX-like shell. [...] D'oh sorry, that should be cmd 2>&1 (redirect fd 2 to the same resource as fd 1 is redirected to (the writing end of the pipe the other end of which is read by the shell to fillup $var)), not cmd >&2 which would redirect stdout to the same resource as fd 1 is redirected to, leaving none of cmd's file descriptor connected to that pipe. > To capture only stdout: > > { var=$(cmd 2>&1 >&3 3>&-); } 3>&1 > > That is we need to redirect cmd's stdout back to what it was > originally (after having redirected cmd's stderr to the pipe), > using that extra fd 3 temporarily. > > That's also standard sh syntax. [...] That one is correct. -- Stephane