Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] Enable further expansion of parameter name by ${!...}
- X-seq: zsh-workers 34380
- From: Tomoki Sekiyama <tomoki.sekiyama@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] Enable further expansion of parameter name by ${!...}
- Date: Sun, 25 Jan 2015 04:15:38 -0500
- Cc: Tomoki Sekiyama <tomoki.sekiyama@xxxxxxxxx>
- 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==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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)"$(<file)"} by skipping
--
1.9.3 (Apple Git-50)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author