Re: Comparing strings

From: Lewis (g.krem...)

In message <[email protected]-email.me> Michael F. Stemper <[email protected]> wrote:
> On 13/07/2021 12.46, ELCV wrote:

>> If I do this:
>>
>> if [ "$1" != "FOO" ];
>> then
>> echo "I can backup the 2nd volume";
>> else
>> exit;
>> fi
>>
>> It works. But if I add an "or" condition as follows:
>>
>> if [ "$1" != "FOO" ] || [ "$1" != "BAR" ] ;

> I've never seen this syntax. I always thought that the "or"
> needed to be within the test, as in:

> if [[ "$1" != "FOO" ||$1 != "BAR" ]]

There's a difference between [[ ]] and [ ] ([[ ]] is superior and you
should probably just get used to using [[ ]] exclusively).

But the syntax used in the sample above is incorrect, i believe, as
single brackets require that you use -o for or.

you really only need to deal with single [ ] if you want to be
compatible with sh.

--
"Are you pondering what I'm pondering?"
"I think so, but where is a fish?"

Share |
Comparing strings... by ELCV on Jul 13th 2021, 17:46
Re: Comparing strings... by Michael F. Stemper on Jul 13th 2021, 21:23