diff --git a/osh/word_eval.py b/osh/word_eval.py index 156f0819c..95a08090e 100644 --- a/osh/word_eval.py +++ b/osh/word_eval.py @@ -1057,13 +1057,31 @@ def _Nullary(self, val, op, var_name, vsub_token, vsub_state): UP_val = val with tagswitch(val) as case: if case(value_e.Undef): - result = value.Str('') + result = value.Str('') # type: value_t elif case(value_e.Str): str_val = cast(value.Str, UP_val) prompt = self.prompt_ev.EvalPrompt(str_val.s) # readline gets rid of these, so we should too. p = prompt.replace('\x01', '').replace('\x02', '') result = value.Str(p) + elif case(value_e.BashArray, value_e.BashAssoc): + if val.tag() == value_e.BashArray: + val = cast(value.BashArray, UP_val) + values = [ + s for s in bash_impl.BashArray_GetValues(val) + if s is not None + ] + elif val.tag() == value_e.BashAssoc: + val = cast(value.BashAssoc, UP_val) + values = bash_impl.BashAssoc_GetValues(val) + else: + raise AssertionError() + + tmp = [ + self.prompt_ev.EvalPrompt(s).replace( + '\x01', '').replace('\x02', '') for s in values + ] + result = value.BashArray(tmp) else: e_die("Can't use @P on %s" % ui.ValType(val), op) diff --git a/spec/var-op-bash.test.sh b/spec/var-op-bash.test.sh index 27384850a..47277dca2 100644 --- a/spec/var-op-bash.test.sh +++ b/spec/var-op-bash.test.sh @@ -300,7 +300,8 @@ status=0 status=0 ## END ## OK osh STDOUT: -status=1 +a b c +status=0 a $'b\\nc' status=0 a a a @@ -328,7 +329,8 @@ A - A status=0 ## END ## OK osh STDOUT: -status=1 +- y +status=0 - y status=0 A - A