Files
D. Ben Knoble 10040bc9cd runtime(sh): allow "#" in special derefs
Code like ${!#} flags the "#" as shDerefWordError [1]; the "!prefix"
syntax region delegates to one of the shDerefSpecial handlers via
@shDerefList, but it misses the "#" case as valid for ${##} and ${!#}.

[1]: https://vi.stackexchange.com/q/48617/10604

Correct that. Indirection is only valid in Bash in Ksh, so rearrange the
"!" handling to be conditional.

closes: #20016

Helped-by: Christian Brabandt <cb@256bit.org>
Signed-off-by: D. Ben Knoble <ben.knoble+github@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2026-04-21 19:59:07 +00:00

38 lines
692 B
Bash

#!/bin/bash
# bash 5.3+ supports command substitution that is very similar
# (but not identical) to ksh/mksh.
echo ${ echo one;}
echo ${ echo two
}
echo ${
echo three ;}
echo ${ echo 'four'; }
echo ${ echo 'five' ;}
echo ${ echo 'six'
}
echo ${ echo 'seven' ;}
echo ${ echo 'eight'; }
typeset nine=${ pwd; }
echo ${ echo 'nine' ;
}
valsubfunc() {
REPLY=$1
}
echo ${|valsubfunc ten;}
echo "${|valsubfunc eleven; }"
printf '%s\n' "${|valsubfunc twelve ;}"
unlucky=${|valsubfunc thirteen
}
typeset notafloat=${|valsubfunc notanumber ;
}
echo $unlucky $notanumber
${|echo fourteen;}
${|echo fifteen
}
echo "${!#}" # last positional argument
echo "${!@}" # deref
echo "${#PATH}" # length