Skip to content

Commit

Permalink
[osh] Implement ${a[@]@p}
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 1, 2025
1 parent fa6c995 commit 9634100
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 19 additions & 1 deletion osh/word_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 4 additions & 2 deletions spec/var-op-bash.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -328,7 +329,8 @@ A - A
status=0
## END
## OK osh STDOUT:
status=1
- y
status=0
- y
status=0
A - A
Expand Down

0 comments on commit 9634100

Please sign in to comment.