Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Subscript flag (i) not working correctly on empty strings?
- X-seq: zsh-workers 51286
- From: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>, Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: Re: Subscript flag (i) not working correctly on empty strings?
- Date: Sat, 7 Jan 2023 14:54:03 +0100
- Archived-at: <https://zsh.org/workers/51286>
- In-reply-to: <CAN=4vMoQNwiFV6_hgbPMvr4F=ESpdmg-qVuRKMtazp-aHzov1Q@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAGdYchuqW79Q3nMguaOrJKEcRwMnQgDRNhHmh3hF5V6sgp=q4g@mail.gmail.com> <361494476.8470860.1673025799682@mail.virginmedia.com> <CAH+w=7Z5=ncO6JXa=qhbXkXkpC_3V5gBSv4eCv=ASXjYmT1zVA@mail.gmail.com> <CAGdYchvfrrRAxdMybUbs8JTj3ii464pxnGptHAUUoiw4xYv8Zw@mail.gmail.com> <CAN=4vMoQNwiFV6_hgbPMvr4F=ESpdmg-qVuRKMtazp-aHzov1Q@mail.gmail.com>
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