From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27679 invoked by alias); 25 Jan 2015 09:15:48 -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: X-Seq: 34380 Received: (qmail 7775 invoked from network); 25 Jan 2015 09:15:47 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=eMfvSWHht67iR+pW5Yq7xK12A2ffMLvlgfs69iCjReI=; b=nLyxIehUipXErHgdQ4VRU3lUjj4Rt7fSDtjjQPVsa9r0XpEcPGVPHN9HerBU4c+OOO 2drw4NcqFYmwai3w//3kAboj+ZOzHsKpapJV3M7V0B3zl6jcAwSjZmieOMhTOw+crUZn LTGcKmtgEW5DzXZEJBhINbB4GA1ca17MrvYK3XMnIW3E0UdRPxxp2AqJEctcKYqDnpb0 sof99saireTuHScJNj17LlUs81n6EUM0AXfCTH2pxHTrwub8Bc3p4nbesUr07u3BaZcy 8N3Nk6iZPPgzgjxr7XE3gTygRNASmnrByikfe2RECzovOgDqXtgJUyUKRwhURi2hUMWQ tQEA== X-Received: by 10.140.102.100 with SMTP id v91mr29654357qge.29.1422177341574; Sun, 25 Jan 2015 01:15:41 -0800 (PST) From: Tomoki Sekiyama To: zsh-workers@zsh.org Cc: Tomoki Sekiyama Subject: [PATCH] Enable further expansion of parameter name by ${!...} Date: Sun, 25 Jan 2015 04:15:38 -0500 Message-Id: <1422177338-85472-1-git-send-email-tomoki.sekiyama@gmail.com> X-Mailer: git-send-email 1.9.3 (Apple Git-50) With this change, ${!...} will enable further expansion of parameter name, which is equivalent to (P) expansion flag. This will enable zsh to run some scripts using variable references for bash. For example: function trueorfalse { local default=$1 local literal=$2 local testval=${!literal} [[ -z "$testval" ]] && { echo "$default"; return; } [[ "0 no No NO false False FALSE" =~ "$testval" ]] && { echo "False"; return; } [[ "1 yes Yes YES true True TRUE" =~ "$testval" ]] && { echo "True"; return; } echo "$default" } echo $(trueorfalse 0 SOME_VAR) --- Doc/Zsh/expn.yo | 5 +++++ Src/subst.c | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index 8728803..1029aef 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -833,6 +833,11 @@ the pattern tt(*.c), which may be expanded by filename generation, but tt(${${~foo}//\*/*.c}) substitutes to the string tt(*.c), which will not be further expanded. ) +item(tt(${!)var(spec)tt(}))( +This is equivalent to 'tt((P))' flag, which forces the value of the +parameter var(name) to be interpreted as a further parameter name, +whose value will be used where appropriate. +) enditem() If a tt(${)...tt(}) type parameter expression or a diff --git a/Src/subst.c b/Src/subst.c index a2bb648..8897350 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2179,6 +2179,10 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) zerr("bad substitution"); return NULL; } + } else if (c == '!') { + /* equivalent to (P) */ + aspar = 1; + s++; } else if (inbrace && inull(*s)) { /* * Handles things like ${(f)"$(