BUG? -> sh: [ "$@" ] -> "eats" it's quotes!

If [ "$@" ] is alone, err won't show up, but if you compare it ...

Code:
debug_fun ()
{
    local -
    set -x

    [ "$1" ] && echo '$1 - Empty!'
    [ "$*" ] && echo '$* - Empty!'
    [ "$@" ] && echo '$@ - Empty!'
}


debug_fun_compare ()
{
    local -
    set -x

    [ "$1" = ro ] && echo '$1 - Empty!'
    [ "$*" = ro ] && echo '$* - Empty!'
    [ "$@" = ro ] && echo '$@ - Empty!'
}


debug_fun

debug_fun_compare
 
[ is expanded like any other simple command. The three tests in your first function are not all expanded the same but all are valid tests returning false. The third test in your second function causes a test(1)() syntax error because "$@" expands to nothing at all if there are no positional parameters.
 
That is exactly, why do I use double quotes around vars, to prevent syntax errors, in case when var isn't set/is undefined.
Problem is, "$@" acts like it was written as $@. It's double quotes disappear (Exposed via set -x in both functions)
 
Back
Top