Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh array subscripting with ksh comp behaviour



On Aug 23,  7:03pm, Peter Stephenson wrote:
} 
} Hence you can test directly for this feature.  As long as the shell
} isn't old enough that the special parameters used by the new completion
} system are absent,
} 
}   zmodload -i zsh/parameter
}   print ${+options[kshzerosubscript]}   

It's too bad that [[ -o there_is_no_such_option ]] is a critical error
rather than returning some kind of falsehood, but you can always test
in any version of the shell with

    if ( [[ -o kshzerosubscript ]] ) >&/dev/null
    then print KSH_ZERO_SUBSCRIPT
    else print not KSH_ZERO_SUBSCRIPT
    fi

Unfortunately this isn't all you need in this case, because the old
behavior occurs when EITHER (a) the option doesn't exist OR (b) the
option is set.

So you end up with something like

    if ( setopt kshzerosubscript ) >&/dev/null &&
       [[ ! -o kshzerosubscript ]]
    then print New zero subscript behavior
    else print Old zero subscript behavior
    fi



Messages sorted by: Reverse Date, Date, Thread, Author