Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
syntax:ccmd:conditional_expression [2015/04/30 11:35] mklement0 [Regular Expression Matching] typo |
syntax:ccmd:conditional_expression [2017/02/08 22:30] (current) fgrose [Table] highlight the consequence of quoting a PATTERN |
||
---|---|---|---|
Line 15: | Line 15: | ||
| ''<EXPRESSION1> **&&** <EXPRESSION2>'' | ''TRUE'' if ''<EXPRESSION1>''**and**''<EXPRESSION2>'' are ''TRUE'' (do **not** use ''-a''!) | | | ''<EXPRESSION1> **&&** <EXPRESSION2>'' | ''TRUE'' if ''<EXPRESSION1>''**and**''<EXPRESSION2>'' are ''TRUE'' (do **not** use ''-a''!) | | ||
| ''<EXPRESSION1> **||** <EXPRESSION2>'' | ''TRUE'' if ''<EXPRESSION1>''**or**''<EXPRESSION2>'' is ''TRUE'' (do **not** use ''-o''!) | | | ''<EXPRESSION1> **||** <EXPRESSION2>'' | ''TRUE'' if ''<EXPRESSION1>''**or**''<EXPRESSION2>'' is ''TRUE'' (do **not** use ''-o''!) | | ||
- | | ''<STRING> **==** <PATTERN>'' | ''<STRING>'' is checked against the pattern ''<PATTERN>'' - ''TRUE'' on a match | | + | | ''<STRING> **==** <PATTERN>'' | ''<STRING>'' is checked against the pattern ''<PATTERN>'' - ''TRUE'' on a match \\ //But note¹, quoting the pattern forces a literal comparison.// | |
| ''<STRING> **=** <PATTERN>'' | equivalent to the ''=='' operator | | | ''<STRING> **=** <PATTERN>'' | equivalent to the ''=='' operator | | ||
| ''<STRING> **!=** <PATTERN>'' | ''<STRING>'' is checked against the pattern ''<PATTERN>'' - ''TRUE'' on **no match** | | | ''<STRING> **!=** <PATTERN>'' | ''<STRING>'' is checked against the pattern ''<PATTERN>'' - ''TRUE'' on **no match** | | ||
| ''<STRING> **=~** <ERE>'' | ''<STRING>'' is checked against the [[https://en.wikipedia.org/wiki/Regular_expression#POSIX_extended|extended regular expression]] ''<ERE>'' - ''TRUE'' on a match | | | ''<STRING> **=~** <ERE>'' | ''<STRING>'' is checked against the [[https://en.wikipedia.org/wiki/Regular_expression#POSIX_extended|extended regular expression]] ''<ERE>'' - ''TRUE'' on a match | | ||
| See the [[commands:classictest#file_tests|classic test operators]] | Do **not** use the ''test''-typical operators ''-a'' and ''-o'' for AND and OR. | | | See the [[commands:classictest#file_tests|classic test operators]] | Do **not** use the ''test''-typical operators ''-a'' and ''-o'' for AND and OR. | | ||
+ | | See also [[syntax:arith_expr#comparisons|arithmetic comparisons]] | Using ''%%(( <EXPRESSION> ))%%'', the [[syntax:ccmd:arithmetic_eval|arithmetic expression compound command]] | | ||
- | When the ''=='' and ''!='' operators are used, the string to the right of the operator is considered a pattern and matched according to the rules of [[syntax:pattern | Pattern Matching]]. If the shell option ''nocasematch'' is enabled, the match is performed without regard to the case of alphabetic characters. Any part of the pattern may be quoted to force it to be | + | When the ''=='' and ''!='' operators are used, the string to the right of the operator is considered a pattern and matched according to the rules of [[syntax:pattern | Pattern Matching]]. If the shell option ''nocasematch'' is enabled, the match is performed without regard to the case of alphabetic characters. |
- | matched as a literal string. | + | |
+ | ¹Any part of the pattern may be quoted to force it to be matched as a literal string. | ||
When the operators ''<'' and ''>'' are used (string collation order), the test happens using the current locale when the ''compat'' level is greater than "40". | When the operators ''<'' and ''>'' are used (string collation order), the test happens using the current locale when the ''compat'' level is greater than "40". |