From patchwork Fri Jan 9 17:17:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Harald van Dijk X-Patchwork-Id: 5601931 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E11889F2ED for ; Fri, 9 Jan 2015 17:17:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 43CD1205FA for ; Fri, 9 Jan 2015 17:17:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EF0CA204A9 for ; Fri, 9 Jan 2015 17:17:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752210AbbAIRRr (ORCPT ); Fri, 9 Jan 2015 12:17:47 -0500 Received: from hosting12.csv-networks.nl ([84.244.151.217]:48294 "EHLO hosting12.csv-networks.nl" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1752002AbbAIRRq (ORCPT ); Fri, 9 Jan 2015 12:17:46 -0500 Received: from home.gigawatt.nl ([83.163.3.213] helo=[192.168.178.26]) by hosting12.csv-networks.nl with esmtpsa (TLSv1:DHE-RSA-AES128-SHA:128) (Exim 4.80) (envelope-from ) id 1Y9dBs-0005lv-Bp for dash@vger.kernel.org; Fri, 09 Jan 2015 18:17:40 +0100 Message-ID: <54B00D36.7070707@gigawatt.nl> Date: Fri, 09 Jan 2015 18:17:42 +0100 From: Harald van Dijk User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: dash Subject: [PATCH] Fix variable assignments in function invocations 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, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, T_TVD_MIME_EPI, 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 all, A long-standing problem with dash has been how it deals with variable assignments in function invocations, and several packages are affected by it, two I've come across recently being autogen and pkg-config (only their test suites, luckily). A short test script: f() { echo inside f, VAR is $VAR sh -c 'echo inside sh called from f, VAR is $VAR' } VAR=value f echo after returning from f, VAR is $VAR Assuming VAR was not already set, this should print (and does with bash): inside f, VAR is value inside sh called from f, VAR is value after returning from f, VAR is With dash, this actually prints: inside f, VAR is value inside sh called from f, VAR is after returning from f, VAR is value The first problem with that is that VAR does not get exported, the second is that VAR's assigned value is kept after the function has returned. Quoting SUSv4 Shell Command Language 2.9.1 Simple Commands: If no command name results, variable assignments shall affect the current execution environment. Otherwise, the variable assignments shall be exported for the execution environment of the command and shall not affect the current execution environment (except for special built-ins). In `VAR=value f`, f is found as the command name. No exception is made for function invocations, so I believe this disallows dash's current behaviour, and requires it to print the same thing bash does. Fixing this seems trivial, see the attachment, and the test suites of both autogen and pkg-config pass with this change. Does this look correct? Cheers, Harald van Dijk --- a/src/eval.c +++ b/src/eval.c @@ -875,7 +875,7 @@ raise: break; case CMDFUNCTION: - poplocalvars(1); + listsetvar(varlist.list, VEXPORT|VSTACK); if (evalfun(cmdentry.u.func, argc, argv, flags)) goto raise; break;