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,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30707 invoked from network); 11 Nov 2020 16:56:34 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 11 Nov 2020 16:56:34 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1605113794; b=lBivakUSDP/mmZRceQAQzPjMr/wwcJO86U02+n+D9oQDMFdyVv+yg3wWivT689/le2M67X+enP ctykKs48/86zAgU9DqcDn+ADs5dH8sDY57N6mI0t46bPrQi2lA7AVf+MpVwXQp0Tqzqc+zRu0P pic48C3kkUzobzpQTBrQpmbZYJaq9bX5M0DRfKL/x/fwf+aBxZifvDGuzsgCov4Rwybcuv2BYX nxeueF6dFt2ZDNtAze3XtJFGKeMTD8AS4VdWQ34twddRwGR6cvBlALwq53dAMh2xyMDVt298Qr Mh40Hin6Bpf3lRzTNA2nB9LaP6lIh73ctUbAAvlz3LZLYg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-wm1-f47.google.com) smtp.remote-ip=209.85.128.47; dkim=pass header.d=gmail.com header.s=20161025 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-20200801; t=1605113794; bh=Zg8NnOFR3I1CJb7k3c5Hyp9tteskQA4ax+OYIoPi/5A=; 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=VRfXmvBkREVc7ixGRv4OM7zFo9piW6Ix8getLfevQHQoAKwRpqHxOj0N77Lc//n634aaI8jGhL s7xj3KDkABnv4u3l/G3g7w4dqjHkhs0WA0cYbjNHoq8ViyiofseXzG9gs/1IdpIfOaJCPuil2X sMFg5H1JG4Bhb4YxEsQk8KSxzI91j5Kxyp5YRSO3kp4FmZzRXMhbCd1wqjeDO9tYrRh81nsLF1 FH7jDIGWm/LLCQ/74L4t0ISLAJcNOwEmd8M2WrkR2nEWAzdWRuR8NacuYp5154WoQ1Ki/A3noD g1pMKYL/OQTQASssp92zClUrqJfe7t5rKx9PL2+eZNUssw==; 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: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=t2qUpKeiBwWgXTkWZcMpY9+NahZYr8HBXa6mFf3sBYQ=; b=va8Qsxl5rIEJbC+nQnfl5pTEKN m0Q18Qrel6ZgtWeCI+18+mZkk8dVRl0ebIjNYoug7OdPTuWJxDdpWnidBBDDBeiWdb3fKC8n3n23W 3m+y9IRbjlrrmgRw8J1DQ0H3vV34BdyqXl0Po7hoCTemojmErJ0JOgD9uaJFmdklPUpYfsSGYZZdc qMMig4TZqP4fE/sErzMWKwoIjNgk22eXFJSzxK7aA508bYr4X7yDzhicul/QVJCexHYJ8wmbPkzMy /WmrSreQmn3c3ziOal2SWt6Wva+B5JzHSTeTW9bejKqhFpPcnRzB/He4Le3nWPIIYjm/IOw3qNawW qr9Oq1Lw==; Received: from authenticated user by zero.zsh.org with local id 1kctQ9-000NZS-RD; Wed, 11 Nov 2020 16:56:33 +0000 Authentication-Results: zsh.org; iprev=pass (mail-wm1-f47.google.com) smtp.remote-ip=209.85.128.47; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-wm1-f47.google.com ([209.85.128.47]:51310) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kctPv-000NQm-L7; Wed, 11 Nov 2020 16:56:20 +0000 Received: by mail-wm1-f47.google.com with SMTP id 19so2902308wmf.1 for ; Wed, 11 Nov 2020 08:56:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=t2qUpKeiBwWgXTkWZcMpY9+NahZYr8HBXa6mFf3sBYQ=; b=P3l3Jf+g7LKFXGrYHSn9lwd8GYSQ9MZ2A4s6NdDF3cCgfPBXt1DBfkVjehDfXrssXZ dnMvFLHJho9FeFYLLZA0wcoS9TD7s1WjZ/tjX0QGh6pjk6eF7XXucxBCbr7adcn5Snmw osEW4mfNOWquQs1J8tmzcpNzz1QCA/SK457yeKJkGcBn/xgHcrXJfokJaoHe6FlKLqqE PVge29aHfPcdYylij5RD6K6wkLS7GD8+7dq4hXUFj1Ou8WW13RQNuz8Qh/yWFD3awCi0 I2bdJ6MGkC5nsiJxGstTiXJm6ZtNOCW4Yc1Zo+Ulv5vQ+2L6VDEkrmICpz8oT6MbyuqJ ll+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=t2qUpKeiBwWgXTkWZcMpY9+NahZYr8HBXa6mFf3sBYQ=; b=i8t5xdobQ5PqGhxlgKzNmZx5jxelK0WmkGlUpFnW5mtTbx8rAZxSbCPqBqU7GdNM+s iR9hEtGi8rLuknIYNljBzYCyzLfSRJ2NbK1IUozPusuR2VULcjvdhOofEtPfy1kfQd1o jx9HLoUc/rRdZiBI3bF7NEhsqduVLSWkr8x7V2lf9wa+tadpt/WXlYJPediWtzBLWsMa wTuYg4TA6yp2VUajpGePPjU4L1gf9z/jQ0cHkdkBHDmYu+rQ4GtdN2qmsl2q2uVwQfEQ fnG+KbyBRoTHUrpHeANcCBHcgNZB8KVsj8c2kPSqFSly3PdmIaaGTN12A3NsWzhO6lGw KS6A== X-Gm-Message-State: AOAM533wDKqxz23dQttmPj+s4YzVPUFDNctm9CzBMTI79mii/MbFbJ9s XVhp/dS2dfy87vObRZG+07VZPdh9xTMUx9XuJnk= X-Google-Smtp-Source: ABdhPJzrlupZS7DjINYAiBNtMhl+EUPGqt/sHqBJo/zRkUr22O9jY1uL/U6DZ+Ux1pwk0kjNaqVkZV1Y/0Iv5foio9M= X-Received: by 2002:a1c:4c09:: with SMTP id z9mr5147984wmf.55.1605113779269; Wed, 11 Nov 2020 08:56:19 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Felipe Contreras Date: Wed, 11 Nov 2020 10:56:08 -0600 Message-ID: Subject: Re: Bug with unset variables To: Roman Perepelitsa Cc: Zsh hackers list Content-Type: text/plain; charset="UTF-8" X-Seq: 47533 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: Archived-At: On Wed, Nov 11, 2020 at 10:13 AM Roman Perepelitsa wrote: > > On Wed, Nov 11, 2020 at 4:57 PM Felipe Contreras > wrote: > > > > Hello, > > > > It's obvious what this code should do: > > > > foo () { > > typeset var > > echo "var: '${var-other}'" > > } > > When foo is invoked, based on the documentation for typeset, I would > expect it to print "var: ''". My main concern is not the documentation of typeset, but useful code. The primary reason for why typeset exists is to set the scope of a variable. Especially so when using "local". If I actually do something on the foo() function: typeset var [[ -n "$1" ]] && var=$1 echo "var: '${var-other}'" I would expect two things: 1) var is not set when I exit the function, and 2) var is not set until I specifically set it. I can get both in ksh and bash, but not in zsh. In zsh I have to choose either 1) with typeset, or 2) by removing typeset. How do you suggest I get both in zsh? > Except as noted below for control flags that change the behav- > ior, a parameter is created for each name that does not already > refer to one. > > And indeed that's how foo behaves when I invoke it in zsh 5.8. It is possible to "create" a parameter without value (indeed that's what happens in other shells), the documentation doesn't say anything about assigning it a default empty string as value. > > I also tried with the other unnamable shell, and the correct output is shown. > From `help local`: > > Create a local variable called NAME, and give it VALUE. > > As far as I can tell, there is no indication anywhere in the > documentation that omitting =VALUE will cause `local` to not create a > variable in bash. The documentation makes it obvious that: local name Creates a local variable called "name". And: local name=value Creates a local variable called "name", and gives it "value" as its value. If you omit the value, then it doesn't assign it any value. As is the case in countless languages; declaring a variable without specifying any value assigns it the value of null (or "unset" in shell lingo). > Do you believe the behavior of bash is expected while zsh behaves > incorrectly? If so, why? Yes, and ksh also behaves correctly. As stated above, it's the only behavior that makes sense. Otherwise you cannot declare a local variable that is unset. Cheers. -- Felipe Contreras