Path: csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail From: William Entriken Newsgroups: gnu.bash.bug Subject: Re: Double substitution issue Date: Wed, 28 Feb 2018 11:13:58 -0500 Lines: 64 Approved: bug-bash@gnu.org Message-ID: References: <5cc476fa-8293-ba55-1325-8d672982ad60@case.edu> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: usenet.stanford.edu 1519834445 25663 208.118.235.17 (28 Feb 2018 16:14:05 GMT) X-Complaints-To: action@cs.stanford.edu Cc: bug-bash@gnu.org To: chet.ramey@case.edu Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=UeM7f+qwmRwHsM5zvbvcB6bVGXy+wiECUXr92c81eXM=; b=J8W9r4sxQx0ceE9bklpZAQQKXrI4R2TX0mWk9xtxpg0Js/XIrM0bDDoN/dAnjxEP6X GnsLomkXkoXmdzqXFZoJaaBNG1CQtLYG81s4DH6enNeUFuvWnXyOWxFKiUrDsZO/PQjJ 49dsuUorIJT1tVfGe2jz6RKCM1wSBLovA9uNtHKhXeKfoHOb8oODghs6P+dTPn34KzpR oEZCXz6I40al3MRkCBpq1tDr2uTrQC95Vo0+wE/XGEcGfw5khKKtGe72/If5u1OyXfjX d2DtsUm5H1WDaAZD0NtKxV7KEZsjYVpR1iQnZLgvuwCyWurStS7uaAKYsp/QJwKvkuTn vSlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=UeM7f+qwmRwHsM5zvbvcB6bVGXy+wiECUXr92c81eXM=; b=fsJl8dRSTfZzNDp5U9fZqYT2VWUzoKWLvRmWd0xhNdOOh2yzSEbTSFg4bbS+OeEJvM IywhLn4o0XxbkIlfq+Dn88evoTxksPrl/V6yQeaPOwAgYJUG2KNPhg1E5W3Wp/fEQiwE 4WD+cHBjk6a7eMLqN2Xq3VH0eDnEWjOdwG9fh14XRzIVv++RVTNaVB2TH/rInItZIf0e 6kR3PPasi0DMUElAPl+wqX75wKxSpgMPz0iF1mq7ulLFw0f4v82BH12cYSGu+igZrGk8 RW1Gnzyrpc/nqytuSB//BY0u2ULEQKxid0X7FNaeI7pjq1FNjttbjVWzUwEyaVTemWDR FSfg== X-Gm-Message-State: APf1xPD4iSMC7WR0fjxBEJZdigPjhNEFNAmL20w+hUIJQ8EmuZhX5GG/ uHYLt1xZqbhwNwj/WVFzZC/lanYjrw+cUw+EFEkEZzKk X-Google-Smtp-Source: AG47ELsMgMpRrPCxl4CKQ1SaMJ/F2WTkrac9g0jyNay6m0mM40kdRln8gd3PT6ARwOov/udEu0Lzu1kUZFTUSpm58Xs= X-Received: by 10.80.206.71 with SMTP id k7mr7431873edj.153.1519834439127; Wed, 28 Feb 2018 08:13:59 -0800 (PST) In-Reply-To: <5cc476fa-8293-ba55-1325-8d672982ad60@case.edu> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::230 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com gnu.bash.bug:13771 Thank you for explaining this fine point. I have found a way to use double expansion, and of course this is not safe in all contexts: from=1;to=3;eval echo {$from..$to} Regards, Will William Entriken +1 267-738-4201 On Wed, Feb 28, 2018 at 10:03 AM, Chet Ramey wrote: > On 2/28/18 3:25 AM, William Entriken wrote: > > This behavior is different in zsh and bash, and maybe bash behavior is a > > bug. > > > > # Test case > > > > touch 1 2 3 > > cat > script.sh < > from=1 > > to=3 > > ls {$from..$to} > > EOL > > chmod a+x script.sh > > > > bash ./script.sh > > > > zsh ./script.sh > > > > # Expected > > > > Both list files 1, 2, 3 > > > > # Actual > > > > zsh passes. > > > > Bash fails the chained substitution with: > > > > ls: {1..3}: No such file or directory > > This is how bash works, how it's always worked, and how it's documented to > work: > > "Brace expansion is performed before any other expansions, and any char- > acters special to other expansions are preserved in the result. It is > strictly textual. Bash does not apply any syntactic interpretation to > the context of the expansion or the text between the braces." > > So you have {$from..$to}, which is not a valid sequence expression because > $from and $to are not integers. Invalid brace expansions are left > unchanged. When the word undergoes parameter expansion, you get {1..3}. > > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/ >