Permalink
Browse files
Implement basic bar ref ${!a}.
Polish var-ref tests.
Addresses issue #26.
- Loading branch information...
Showing
with
30 additions
and
19 deletions.
-
+4
−1
core/word_eval.py
-
+24
−17
spec/var-ref.test.sh
-
+2
−1
test/spec.sh
|
|
@@ -434,8 +434,11 @@ def _ApplyPrefixOp(self, val, op_id): |
|
|
# TODO: There can be empty placeholder values in the array.
|
|
|
length = len(val.strs)
|
|
|
return runtime.Str(str(length))
|
|
|
elif op_id == Id.VSub_Bang:
|
|
|
# Treat the value of the variable as a variable name.
|
|
|
return self.mem.GetVar(val.s)
|
|
|
else:
|
|
|
raise NotImplementedError(op_id)
|
|
|
raise AssertionError(op_id)
|
|
|
|
|
|
def _ApplyOtherSuffixOp(self, val, op):
|
|
|
|
|
|
|
|
|
@@ -4,6 +4,30 @@ |
|
|
#
|
|
|
# http://stackoverflow.com/questions/16461656/bash-how-to-pass-array-as-an-argument-to-a-function
|
|
|
|
|
|
### var ref ${!a}
|
|
|
a=b
|
|
|
b=c
|
|
|
echo ref ${!a} ${a}
|
|
|
# Woah mksh has a completely different behavior -- var name, not var ref.
|
|
|
# stdout: ref c b
|
|
|
# BUG mksh stdout: ref a b
|
|
|
# N-I dash/zsh stdout-json: ""
|
|
|
|
|
|
### declare -n and ${!a}
|
|
|
declare -n a
|
|
|
a=b
|
|
|
b=c
|
|
|
echo ${!a} ${a}
|
|
|
# stdout: b c
|
|
|
# N-I mksh stdout: a b
|
|
|
|
|
|
### Bad var ref with ${!a}
|
|
|
#set -o nounset
|
|
|
a='bad var name'
|
|
|
echo ref ${!a}
|
|
|
echo status=$?
|
|
|
# stdout-json: "ref\nstatus=0\n"
|
|
|
# BUG mksh stdout-json: "ref a\nstatus=0\n"
|
|
|
### pass array by reference
|
|
|
show_value() {
|
|
|
local -n array=$1
|
|
|
@@ -42,20 +66,3 @@ caller |
|
|
# BUG mksh stdout-json: ""
|
|
|
# BUG mksh status: 1
|
|
|
|
|
|
### Var ref with ${!a}
|
|
|
a=b
|
|
|
b=c
|
|
|
echo ref ${!a}
|
|
|
# Woah mksh has a completely different behavior -- var name, not var ref.
|
|
|
# stdout: ref c
|
|
|
# BUG mksh stdout: ref a
|
|
|
# N-I dash/zsh stdout-json: ""
|
|
|
|
|
|
### Bad var ref with ${!a}
|
|
|
#set -o nounset
|
|
|
a='bad var name'
|
|
|
echo ref ${!a}
|
|
|
# Woah even dash implements this!
|
|
|
# stdout-json: "ref\n"
|
|
|
# BUG mksh stdout: ref a
|
|
|
# N-I dash/zsh stdout-json: ""
|
|
|
@@ -452,7 +452,8 @@ extended-glob() { |
|
|
|
|
|
# ${!var} syntax -- oil should replace this with associative arrays.
|
|
|
var-ref() {
|
|
|
sh-spec spec/var-ref.test.sh $BASH $MKSH "$@"
|
|
|
sh-spec spec/var-ref.test.sh --osh-failures-allowed 4 \
|
|
|
$BASH $MKSH $OSH "$@"
|
|
|
}
|
|
|
|
|
|
let() {
|
|
|
|
0 comments on commit
37d5490