From 91ce8291d0beaa816258dbd273e947df7b20ca31 Mon Sep 17 00:00:00 2001 From: Koichi Murase Date: Wed, 25 Dec 2024 17:08:33 +0900 Subject: [PATCH] [osh] Fix `${a[@]@a}` to generate an attribute for each element --- osh/word_eval.py | 13 ++++++++++++- spec/var-op-bash.test.sh | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/osh/word_eval.py b/osh/word_eval.py index 569511c35..156f0819c 100644 --- a/osh/word_eval.py +++ b/osh/word_eval.py @@ -1129,7 +1129,18 @@ def _Nullary(self, val, op, var_name, vsub_token, vsub_state): if cell.nameref: chars.append('n') - result = value.Str(''.join(chars)) + count = 1 + with tagswitch(val) as case: + if case(value_e.Undef): + count = 0 + elif case(value_e.BashArray): + val = cast(value.BashArray, UP_val) + count = bash_impl.BashArray_Count(val) + elif case(value_e.BashAssoc): + val = cast(value.BashAssoc, UP_val) + count = bash_impl.BashAssoc_Count(val) + + result = value.BashArray([''.join(chars)] * count) else: e_die('Var op %r not implemented' % lexer.TokenVal(op), op) diff --git a/spec/var-op-bash.test.sh b/spec/var-op-bash.test.sh index 1bbb7badd..27384850a 100644 --- a/spec/var-op-bash.test.sh +++ b/spec/var-op-bash.test.sh @@ -303,7 +303,7 @@ status=0 status=1 a $'b\\nc' status=0 -a +a a a status=0 ## END