简体   繁体   English

比较bash中的两个字符串

[英]compare two strings in bash

I'd like to compare two strings and then another two strings. 我想比较两个字符串,然后再比较两个字符串。 So if $version is not equal to 5 and type is not equal to dbma OR if $version is not equal to 6 and $type is not equal to dbmy 因此,如果$ version不等于5且type不等于dbma或$ version不等于6且$ type不等于dbmy

I can't quite get the syntax right. 我不太正确的语法。

if [[ "${version}" != "5" ]] &&  [[ "${type}" != "dbma" ]] || [[ "${version}" != "6" ]] &&  [[ "${type}" != "dbmy" ]]
then
   xyz
else
   abc
fi

Can someone please help? 有人可以帮忙吗?

Assuming this is what you actually mean ... 假设这实际上是您的意思...

if [[ ($version != 5 && $type != "dbma") || ($version != 6 && type != "dbmy") ]]

The [[ built-in allows parentheses and logical operators within the expression (whereas legacy [ had neither, and newer versions have -a and -o for "and" and "or", but no parentheses). [[内置允许在表达式内使用括号和逻辑运算符(而传统[则不提供,而较新的版本在“ and”和“ or”中具有-a-o ,但没有括号)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM