A NOTE has been added to this issue. ====================================================================== http://austingroupbugs.net/view.php?id=375 ====================================================================== Reported By: dwheeler Assigned To: ajosey ====================================================================== Project: 1003.1(2008)/Issue 7 Issue ID: 375 Category: Shell and Utilities Type: Enhancement Request Severity: Objection Priority: normal Status: Under Review Name: David A. Wheeler Organization: User Reference: Section: test Page Number: 3224-3225 Line Number: 107503-107513 Interp Status: --- Final Accepted Text: ====================================================================== Date Submitted: 2011-02-07 18:34 UTC Last Modified: 2016-09-21 10:20 UTC ====================================================================== Summary: Extend test/[...] conditionals: ==, <, >, -nt, -ot, -ef ====================================================================== Relationships ID Summary ---------------------------------------------------------------------- has duplicate 0000762 Add "==" as synonym for "... related to 0000813 Utility numeric argument syntax require... ======================================================================
---------------------------------------------------------------------- (0003387) stephane (reporter) - 2016-09-21 10:20 http://austingroupbugs.net/view.php?id=375#c3387 ---------------------------------------------------------------------- Let me rephrase. [[ =~ ]] in ksh93 and bash32+ is a bit broken by design, but to use it properly in both (which seems to be the intent of this proposal: to specify an operator compatible with both), it seems we need (for the argument after =~) to: - quote &, <, >, blanks (locale-dependant (*)) and unmatched ) and some unmatched ] at least or we'd get errors in bash or ksh93 - *not* quote the ERE operators (.*?+[]{}()|$^) if we want them to retain their special ERE significance. You'll notice that several of those (()|) can't be in WORD - quote `, ~, $ and quotes to remove their special meaning as shell tokens (but not inside [...] for some) - to remove the special meaning of those ERE operators, we can use double quotes, single quotes, backslash or $'...' but not when they're inside [...]. - other characters can be quoted as well but not with backslash as that could introduce ERE extensions like \<, \>, \b, \w in ksh93. - for parts of the arguments that are the result of an unquoted expansion other than ~ expansion, \ (in the content of the expansion) removes the special meaning of ERE operators and may introduce new ones. Examples: a='<foo>' bash -c '[[ $a =~ <.*> ]]' gives an error a='foo' ksh93 -c '[[ $a =~ \<.*\> ]]' returns true (\<, \> taken as word boundaries) You need to use: a='<foo>' shell -c '[[ $a =~ "<".*">" ]]' so it works in both shells or a='<foo>' shell -c 're="<.*>"; [[ $a =~ $re ]]' which also works in zsh and bash31 Other example: a='blah' shell -c '[[ $a =~ [xy)] ]]' gives an error in both ksh and bash a='\' shell -c '[[ $a =~ [xy\)] ]]' doesn't give an error but matches in ksh (not in bash). and [[ $a =~ [xy")"] ]] also matches on backslash in ksh93, bash used to have a similar bug. a='blah' shell -c 're="[xy)]"; [[ $a =~ $re ]]' works in all shells (zsh, bash31 included) (*) as already discussed, since blank recognition is locale dependant, you get behaviours like: $ LC_CTYPE=fr_FR.ISO8859-15@euro bash -c '[[ $a =~ tête-à-tête ]]' bash: -c: line 0: syntax error in conditional expression bash: -c: line 0: syntax error near `tête-à-tête' bash: -c: line 0: `[[ $a =~ tête-à-tête ]]' as that à UTF-8 character is 0xc3 0xa0 and 0xa0 happens to be a blank in ISO8859-15 locales on Solaris. So in effect you may need to quote every character that is not in the portable character set in case they may be a blank in the user's locale. Issue History Date Modified Username Field Change ====================================================================== 2011-02-07 18:34 dwheeler New Issue 2011-02-07 18:34 dwheeler Status New => Under Review 2011-02-07 18:34 dwheeler Assigned To => ajosey 2011-02-07 18:34 dwheeler Name => David A. Wheeler 2011-02-07 18:34 dwheeler Section => test 2011-02-07 18:34 dwheeler Page Number => 3224-3225 2011-02-07 18:34 dwheeler Line Number => 107503-107513 2011-02-07 18:49 dwheeler Note Added: 0000666 2011-02-07 20:23 Don Cragun Interp Status => --- 2011-02-07 20:23 Don Cragun Note Added: 0000667 2011-02-07 20:23 Don Cragun Severity Editorial => Objection 2011-02-07 20:23 Don Cragun Type Clarification Requested => Enhancement Request 2011-02-07 21:56 dwheeler Note Added: 0000668 2011-02-07 22:20 Don Cragun Description Updated 2011-02-07 22:20 Don Cragun Desired Action Updated 2011-02-07 22:22 Don Cragun Note Edited: 0000667 2011-02-07 22:50 dwheeler Note Added: 0000669 2011-02-07 23:13 eblake Note Added: 0000670 2011-03-08 03:15 dwheeler Note Added: 0000688 2011-04-24 13:16 jsonn Note Added: 0000754 2011-04-24 19:01 dwheeler Note Added: 0000755 2011-04-24 21:48 jsonn Note Added: 0000756 2011-04-25 20:45 dwheeler Note Added: 0000758 2011-04-26 09:25 markh Note Added: 0000759 2011-04-26 09:57 wpollock Note Added: 0000760 2011-04-26 10:36 jsonn Note Added: 0000761 2011-09-22 08:59 ajosey Note Added: 0000967 2011-09-25 00:36 dwheeler Note Added: 0000974 2011-09-25 18:51 gber Note Added: 0000975 2011-09-28 07:09 olof Issue Monitored: olof 2011-11-15 17:26 dwheeler Note Added: 0001011 2011-11-15 19:25 ajosey File Added: Extendingshellconditionals.pdf 2011-11-15 19:27 ajosey File Added: Extendingshellconditionals.txt 2011-11-15 19:30 ajosey Note Added: 0001013 2011-11-23 23:49 dwheeler File Added: Extendingshellconditionals-2011-11-23.pdf 2011-11-23 23:50 dwheeler File Added: Extendingshellconditionals-2011-11-23.odt 2011-11-23 23:50 dwheeler File Added: Extendingshellconditionals-2011-11-23.txt 2011-11-23 23:57 dwheeler Note Added: 0001044 2011-11-28 15:50 geoffclare Note Added: 0001060 2011-11-28 15:51 geoffclare File Added: Extendingshellconditionals-2011-11-28.odt 2011-11-28 15:52 geoffclare File Added: Extendingshellconditionals-2011-11-28.pdf 2011-11-28 16:10 geoffclare Note Edited: 0001060 2011-11-28 16:38 dwheeler Note Added: 0001061 2011-11-29 03:26 Roger Marquis Note Added: 0001064 2011-11-29 03:27 Roger Marquis Note Edited: 0001064 2011-11-29 04:51 dwheeler Note Added: 0001065 2011-12-29 19:01 antoinel Issue Monitored: antoinel 2013-10-10 01:15 dwheeler Note Added: 0001869 2013-10-12 04:08 dwheeler Note Added: 0001881 2013-10-24 15:15 geoffclare File Added: Extendingshellconditionals-2013-10-24.odt 2013-10-24 15:16 geoffclare File Added: Extendingshellconditionals-2013-10-24.pdf 2013-10-24 15:23 geoffclare Note Added: 0001944 2013-10-25 10:26 geoffclare Note Added: 0001945 2013-10-31 15:55 Don Cragun Relationship added has duplicate 0000762 2013-11-01 15:36 ranjit Note Added: 0001950 2013-11-01 19:09 dwheeler Note Added: 0001953 2013-11-01 19:43 shware_systems Note Added: 0001954 2013-11-10 14:46 dwheeler Note Added: 0001979 2013-11-22 22:13 dwheeler Note Added: 0002017 2013-11-29 18:56 dwheeler File Added: Extendingshellconditionals-2013-11-29.odt 2013-11-29 18:57 dwheeler File Added: Extendingshellconditionals-2013-11-29-track-changes.pdf 2013-11-29 18:58 dwheeler File Added: Extendingshellconditionals-2013-11-29.pdf 2013-11-29 19:11 dwheeler Note Added: 0002031 2013-11-29 19:24 dwheeler Note Added: 0002032 2013-12-01 22:52 jilles Note Added: 0002033 2013-12-02 08:59 shware_systems Note Added: 0002034 2013-12-02 11:15 shware_systems Note Added: 0002035 2013-12-08 22:06 dwheeler Note Added: 0002052 2013-12-08 22:48 dwheeler Note Added: 0002053 2013-12-08 23:05 dwheeler Note Added: 0002054 2013-12-09 01:32 dwheeler File Added: Extendingshellconditionals-2013-12-08.odt 2013-12-09 01:33 dwheeler File Added: Extendingshellconditionals-2013-12-08.pdf 2013-12-09 01:35 dwheeler Note Added: 0002055 2013-12-09 06:55 shware_systems Note Added: 0002056 2013-12-10 04:46 dwheeler Note Added: 0002059 2013-12-10 04:52 dwheeler File Added: Extendingshellconditionals-2013-12-09.odt 2013-12-10 04:53 dwheeler File Added: Extendingshellconditionals-2013-12-09.pdf 2013-12-10 09:41 shware_systems Note Added: 0002060 2013-12-10 16:08 dwheeler Note Added: 0002061 2013-12-10 22:36 jilles Note Added: 0002063 2013-12-11 00:46 dwheeler Note Added: 0002064 2013-12-11 00:48 shware_systems Note Added: 0002065 2013-12-11 00:58 dwheeler Note Added: 0002066 2013-12-12 01:38 shware_systems Note Added: 0002068 2013-12-12 06:04 shware_systems Note Edited: 0002068 2014-03-06 17:08 eblake Relationship added related to 0000813 2014-03-06 17:15 geoffclare Note Added: 0002176 2014-03-06 19:13 ranjit Note Added: 0002177 2014-03-06 21:22 shware_systems Note Added: 0002178 2014-03-07 15:46 dwheeler Note Added: 0002179 2014-03-07 15:52 dwheeler Note Added: 0002180 2014-03-11 14:52 shware_systems Note Added: 0002181 2014-03-12 23:05 dwheeler Note Added: 0002182 2014-03-14 13:25 ranjit Note Added: 0002186 2014-10-13 16:44 rhansen Note Added: 0002418 2014-10-13 16:52 geoffclare Note Added: 0002419 2014-10-13 16:55 dwheeler Note Added: 0002420 2014-10-13 17:54 rhansen Note Added: 0002421 2016-09-19 21:46 stephane Note Added: 0003382 2016-09-20 17:16 shware_systems Note Added: 0003383 2016-09-20 20:34 stephane Note Added: 0003384 2016-09-20 21:03 stephane Note Added: 0003385 2016-09-20 21:07 stephane Note Edited: 0003385 2016-09-21 07:35 shware_systems Note Added: 0003386 2016-09-21 10:20 stephane Note Added: 0003387 ======================================================================