help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Not matching string with wildcard in if statement


From: Andreas Kusalananda Kähäri
Subject: Re: Not matching string with wildcard in if statement
Date: Mon, 9 Mar 2020 17:57:32 +0100

On Mon, Mar 09, 2020 at 11:29:45AM -0500, Jesse Hathaway wrote:
> On Mon, Mar 9, 2020 at 11:21 AM Jeffrey Walton <address@hidden> wrote:
> >     # Echo variables
> >     IOS_SDK: iPhoneOS
> >     IOS_CPU: armv7s
> >     # set -x
> >     +++[[ iPhoneOS == \i\P\h\o\n\e\O\S ]]
> >     +++[[ armv7s == \a\r\m\v\7\* ]]
> >     +++[[ iPhoneOS == \i\P\h\o\n\e\O\S ]]
> >     +++[[ armv7s == \a\r\m\6\4 ]]
> >     ...
> >
> > Why am I failing to match the string "armv7s" with "armv7*" ?
> 
> If you quote the right hand side of a `==` test then you test for
> string equality.
> 
> If you want to test against a glob then the right hand side needs to
> be unquoted,


This is correct, but "armv7"* would also have worked, i.e. the * needs
to be unquoted but the rest of the right hand side can remain quoted
(this make more sense with a pattern such as "$string"* in the case
where $string needs to be matched literally).


Kusalananda


-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]