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

Re: Subscript flag (i) not working correctly on empty strings?



On Sat, Jan 7, 2023 at 2:52 PM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> Whenever I need to check whether a string/array contains a
> character/element, I do it like this:
>
>     if (( $input[(I):] )); then
>       print 'input contains colon'
>     fi

Correction: for strings I use pattern matching.

  if [[ $input == *:* ]]; then
    print 'input contains colon'
  fi

The code I posted above is for arrays (even though it works for strings, too).

Roman.




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