From patchwork Mon Nov 17 21:49:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephane Chazelas X-Patchwork-Id: 5323831 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-dash@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8EEB29F2ED for ; Mon, 17 Nov 2014 21:50:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B6D1F2012B for ; Mon, 17 Nov 2014 21:50:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D393E20120 for ; Mon, 17 Nov 2014 21:50:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751489AbaKQVuP (ORCPT ); Mon, 17 Nov 2014 16:50:15 -0500 Received: from plane.gmane.org ([80.91.229.3]:41670 "EHLO plane.gmane.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbaKQVuO (ORCPT ); Mon, 17 Nov 2014 16:50:14 -0500 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1XqUBZ-00034G-0p for dash@vger.kernel.org; Mon, 17 Nov 2014 22:50:13 +0100 Received: from 5ec33b79.skybroadband.com ([94.195.59.121]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 17 Nov 2014 22:50:13 +0100 Received: from stephane.chazelas by 5ec33b79.skybroadband.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 17 Nov 2014 22:50:13 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: dash@vger.kernel.org From: Stephane Chazelas Subject: command substitutions in $PS4 Date: Mon, 17 Nov 2014 21:49:32 +0000 Lines: 60 Message-ID: <20141117214931.GA4601@chaz.gmail.com> Mime-Version: 1.0 X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: 5ec33b79.skybroadband.com Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hello. [tested on current git head f6d4def4e27b13fab174e948b94cd10550d3e10e] Command substitution doesn't seem to work in $PS4 (used for xtrace prompt): $ PS4='$(date +%T)> ' dash -xc : dash: 1: Syntax error: end of file unexpected (expecting ")") And with the old syntax: $ PS4='`date +%T`> ' dash -xc : > : And with more than one command: $ PS4='`date +%T`> ' dash -xc ':;:' > : dash doesn't return and seems to go in a forking loop, presumably because the `date` there triggers another PS4 expansion and so on recursively If I prevent the recursion with: $ PS4='`date +%T`> ' ./src/dash -xc ':;sleep 1; date' > : 21:43:47> sleep 1 21:43:48> date Mon Nov 17 21:43:48 GMT 2014 The command substitution still fails upon the first expansion only. I quickly gave up trying to find out why as I found the code there hard to follow. --- a/src/eval.c +++ b/src/eval.c @@ -776,7 +776,15 @@ evalcommand(union node *cmd, int flags) int sep; out = &preverrout; + + /* + * reset xflag temporarily for command substitutions performed + * upon $PS4 expansion + */ + xflag = 0; outstr(expandstr(ps4val()), out); + xflag = 1; + sep = 0; sep = eprintlist(out, varlist.list, sep); eprintlist(out, arglist.list, sep);