Thu, 21 Dec 2017 18:13:19 +0100
Daniel Caillibaud <[email protected]> écrivait :

> Pourquoi ?
> 
> $ [[ 'abcd' =~ '^ab' ]] && echo ok || echo KO
> KO
> 
> $ [[ 'abcd' =~ 'cd$' ]] && echo ok || echo KO
> KO
> 
> ??

Parce qu'entre guillemets, les caractères ^ et $ sont considérés comme des 
caractères normaux.

$ set -x

$ [[ 'abcd' =~ '^ab' ]] && echo ok || echo KO
+ [[ abcd =~ \^ab ]]
+ echo KO
KO

$ [[ 'abcd' =~ ^'ab' ]] && echo ok || echo KO
+ [[ abcd =~ ^ab ]]
+ echo ok
ok

$ [[ 'abcd' =~ 'cd$' ]] && echo ok || echo KO
+ [[ abcd =~ cd\$ ]]
+ echo KO
KO

$ [[ 'abcd' =~ 'cd'$ ]] && echo ok || echo KO
+ [[ abcd =~ cd$ ]]
+ echo ok
ok

un petit "set -x" fonctionne bien, même dans une session interactive.

Joyeux Noël !!!

Jean-Marc <[email protected]>

Attachment: pgpopTYwZiT5x.pgp
Description: PGP signature

Répondre à