[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Quoting near =~ is inconsistent
From: |
Kevin F. Quinn |
Subject: |
Quoting near =~ is inconsistent |
Date: |
Sun, 14 Jan 2007 20:25:54 +0100 |
Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: i686-pc-linux-gnu-gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu'
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash'
-DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -ggdb2 -O2
-march=pentium3 -pipe -Wall -Wstack-protector -Wtrampolines uname
output: Linux c1358217 2.6.18-hardened #4 PREEMPT Wed Dec 20 23:25:36
CET 2006 i686 Mobile Intel(R) Pentium(R) III CPU - M 1200MHz
GenuineIntel GNU/Linux Machine Type: i686-pc-linux-gnu
Bash Version: 3.2
Patch Level: 9
Release Status: release
Description:
Matching on =~ is inconsistent with == et. al.
I see there's a FAQ entry mentioning that the rhs of =~ is
automatically interpreted as a string, but I don't think
it means the behaviour below is expected. It means the only
way of expressing strings containing characters meaningful
to the shell, is to escape them. The behaviour in bash-3.1
is consistent with other comparison operators. It seems that
with '=~', quotes on a literal string in the rhs are considered
part of the text to match - traditionally I'd have written that
by escaping the quotes if I wanted to match them.
Repeat-By:
$ v="Alphabet"
$ [[ ${v} == "Alphabet" ]] && echo matches
matches
$ [[ ${v} == 'Alphabet' ]] && echo matches
matches
$ [[ ${v} == Alphabet ]] && echo matches
matches
$ [[ ${v} =~ "Alphabet" ]] && echo matches
$ [[ ${v} =~ 'Alphabet' ]] && echo matches
$ [[ ${v} =~ Alphabet ]] && echo matches
matches
$ v="one two buckle my shoe"
$ [[ ${v} =~ "one two" ]] && echo matches
$ [[ ${v} =~ one two ]] && echo matches
<syntax error, obviously>
$ [[ ${v} =~ one\ two ]] && echo matches
matches
--
Kevin F. Quinn
signature.asc
Description: PGP signature
- Quoting near =~ is inconsistent,
Kevin F. Quinn <=