Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
syntax:ccmd:conditional_expression [2015/04/30 11:34] mklement0 wording (clarity) |
syntax:ccmd:conditional_expression [2017/02/06 23:55] fgrose [Description] Added note on quoted <PATTERN> forcing literal matching |
||
---|---|---|---|
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 see the note on quoting the pattern below¹. | |
| ''<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". | ||
Line 90: | Line 92: | ||
</code> | </code> | ||
- | The interpretion of quoted regular expression special characters can be influenced by setting the ''compat31'' and ''compat32'' shell options (''compat*'' in general). See [[internals:shell_options]]. | + | The interpretation of quoted regular expression special characters can be influenced by setting the ''compat31'' and ''compat32'' shell options (''compat*'' in general). See [[internals:shell_options]]. |
==== Behaviour differences compared to the builtin test command ==== | ==== Behaviour differences compared to the builtin test command ==== |