magicant / yash

Yet another shell
http://magicant.github.io/yash/
GNU General Public License v2.0
330 stars 30 forks source link

Result of tilde expansion in nested parameter expansion #27

Open magicant opened 1 year ago

magicant commented 1 year ago

(Issue migrated from https://osdn.net/projects/yash/ticket/40707)

Currently, the result of ~ and ${unset-~} are not subject to field splitting or pathname expansion, but that of ${${unset-~}} is. Can we prevent expansion for the latter, too?

test_oE 'result of tilde expansion in nested parameter expansion'
HOME='/path/with  $space$(:)`:`$((1))' IFS=' /'
echoraw ${${u-~}}
HOME='*'
echoraw ${${u-~}}
__IN__
/path/with  $space$(:)`:`$((1))
*
__OUT__

In the current implementation, the outer expansion receives the result of the inner expansion after it has performed quote removal. To honor the character origin of the inner expansion, however, the outer expansion needs to receive the result without quote removal. This will affect the character count in the outer expansion; for example, should ${${unset-"~"}[1]} expand to a double-quote or tilde?