From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28650 invoked by alias); 17 Oct 2017 07:01:20 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 41918 Received: (qmail 2285 invoked by uid 1010); 17 Oct 2017 07:01:20 -0000 X-Qmail-Scanner-Diagnostics: from aok120.rev.netart.pl by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(85.128.245.120):SA:0(-1.9/5.0):. Processed in 0.490968 secs); 17 Oct 2017 07:01:20 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: psprint@zdharma.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | X-Virus-Scanned: by amavisd-new using ClamAV (16) Date: Tue, 17 Oct 2017 09:01:17 +0200 From: Sebastian Gniazdowski To: zsh-workers@zsh.org Message-ID: Subject: Documentation for code execution in substitutions using patterns X-Mailer: Airmail (442) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, Zsh has very flexible substitutions. So flexible that I was able to write= ZUI library, and if I was to port it to e.g. python, it would be probabl= y hard if not impossible. But I think the most powerful part =E2=80=93 co= de execution =E2=80=93 isn't documented and isn't always active. =46or ex= ample: % local -A map=3D( a 1 b 2 ); str=3D=22abc=22; echo =22=24=7Bstr//(=23m)=3F= /=24=7Bmap=5B=24MATCH=5D=7D=7D=22 12 %=C2=A0unsetopt extendedglob % local -A map=3D( a 1 b 2 ); str=3D=22abc=22; echo =22=24=7Bstr//(=23m)=3F= /=24=7Bmap=5B=24MATCH=5D=7D=7D=22 abc If (=23m) alone (without e-glob) could do code execution then a more mini= malistic code could be written (no need for localoptions extendedglob). O= ther example: % line=3D0; arr=3D( a b c d ); echo =24=7Barr=5B=40=5D//(=23b)(*)/=24(( += +line ))=7D 1 2 3 4 %=C2=A0line=3D0; arr=3D( a b c d ); echo =24=7Barr=5B=40=5D//(=23b)*/=24(= ( ++ line ))=7D 1 1 1 1 (=23b) needs extendedglob so no additional variations here. One more less= -meaningful substitution: % line=3D0; arr=3D( a b c d ); echo =24=7Barr=5B=40=5D//(*)/=24(( ++ line= ))=7D 1 1 1 1 Maybe there's something more on this topic=3F These nuances could be docu= mented after explaining why above variations exist=3F -- =20 Sebastian Gniazdowski psprint /at/ zdharma.org