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

Re: alias with a parameter



Bart Schaefer wrote on Thu, Apr 15, 2021 at 11:19:16 -0700:
> On Wed, Apr 14, 2021 at 4:10 AM zzapper <zsh@xxxxxxxxxxxxxx> wrote:
> >    if [ $# -gt 0 ] ; then
> 
> It's generally preferable to use [[ ... ]] instead of [ ... ] because
> "[" is just another name for "test" and "]" is just one of its
> arguments, whereas "[[" and "]]" are syntax tokens with parsing rules
> for what appears between them.  However, since you're comparing
> numbers, you could use (( $# > 0 )) here.

In general, «(( ${+foo[1]} ))» is faster than «(( ${#foo} ))», because
the latter takes O(N) time where N is the length of the array, where's
the former is O(1).  For the positional arguments, that'd be «(( $+1 ))».




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