On Wed, Jul 5, 2023, at 9:01 PM, Wiley Young wrote:
> Here's some code as observed "in the wild:"
>
>   `[[ ${#@} -ne 0 ]] && ...`
>
> Perhaps the parser is reading this as an incomplete parameter
> transformation? It seems from context that the original intent was simply...
>
>   `[[ $# -ne 0 ]] && ...`
>
> As it happens, the effect appears to be the same either way, but unless I'm
> missing something, as syntax ${#@} appears to be undefined.

That syntax is defined and documented.

        ${#parameter}

                The length in characters of the expanded value of
                parameter is substituted.  If parameter is '*' or
                '@', the value substituted is the number of positional
                parameters.

https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

-- 
vq

Reply via email to